Currently the CLI appears to be designed for use as a single-shot. However, if KSP is invoked programmatically in a reused thread (such as in github.com/zacsweers/kotlin-compile-testing for unit testing), this becomes a source of memory leaks. It gets worse when tests are spread across multiple threads/workers as well. I've worked around this now in that library by manually clearing that after each run.
https://github.com/google/ksp/blob/main/kotlin-analysis-api/src/main/kotlin/com/google/devtools/ksp/impl/KSPCoreEnvironment.kt#L25-L26
Currently the CLI appears to be designed for use as a single-shot. However, if KSP is invoked programmatically in a reused thread (such as in github.com/zacsweers/kotlin-compile-testing for unit testing), this becomes a source of memory leaks. It gets worse when tests are spread across multiple threads/workers as well. I've worked around this now in that library by manually clearing that after each run.
https://github.com/google/ksp/blob/main/kotlin-analysis-api/src/main/kotlin/com/google/devtools/ksp/impl/KSPCoreEnvironment.kt#L25-L26