Skip to content

Commit

Permalink
[AA Standalone] Provide workaround entry point for low memory watcher…
Browse files Browse the repository at this point in the history
… shutdown

- Dokka cannot call `shutdownApplicationScheduledExecutorService` on its
  own, so a Standalone endpoint is required.
- This endpoint is just a workaround, so it's likely to change in the
  near future. The issue requires proper design.

^KT-71862
  • Loading branch information
marcopennekamp committed Nov 21, 2024
1 parent 3675473 commit d5e988c
Showing 1 changed file with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import com.intellij.openapi.project.Project
import com.intellij.openapi.util.Disposer
import com.intellij.psi.PsiFile
import com.intellij.psi.search.GlobalSearchScope
import com.intellij.util.concurrency.AppExecutorUtil
import org.jetbrains.kotlin.analysis.api.KaExperimentalApi
import org.jetbrains.kotlin.analysis.api.platform.KotlinPlatformSettings
import org.jetbrains.kotlin.analysis.api.platform.declarations.KotlinAnnotationsResolverFactory
Expand Down Expand Up @@ -263,3 +264,22 @@ public inline fun buildStandaloneAnalysisAPISession(
classLoader
).apply(init).build()
}

/**
* Disposes global resources which would persist after unloading Analysis API and IJ platform classes.
*
* **Important:** Once this function has been called, Analysis API *and* IntelliJ platform classes should not be used anymore. The classes
* should either be unloaded or the whole program should be shut down.
*
* You don't need to use this endpoint right before your program shuts down. The purpose of this function is rather to dispose global
* resources which would persist after unloading Analysis API and IJ platform classes. For example, an IJ platform class may be registered
* with a JDK class. If Analysis API & IJ platform classes are unloaded, this global registration may keep alive the old class loader.
*
* Note: Everything in Standalone is experimental, but this endpoint is likely to change in the *near future*. Please consult with the
* Analysis API team if you want to use this. (We'll want to know about your use case.)
*/
@Suppress("UnstableApiUsage")
@KaExperimentalApi
public fun disposeGlobalStandaloneApplicationServices() {
AppExecutorUtil.shutdownApplicationScheduledExecutorService()
}

0 comments on commit d5e988c

Please sign in to comment.