Fix project leaking in tests

The project was leaking via MockApplication -> LowMemoryWatcherManager -> List<Project>
It happened due to unregistered disposable provided to the MockApplication
This commit is contained in:
Ilya Kirillov
2021-07-21 19:48:40 +02:00
committed by teamcityserver
parent f19dfd9d2a
commit 77fcb12af8
2 changed files with 9 additions and 1 deletions
@@ -543,7 +543,14 @@ class KotlinCoreEnvironment private constructor(
): KotlinCoreApplicationEnvironment {
synchronized(APPLICATION_LOCK) {
if (ourApplicationEnvironment == null) {
val disposable = Disposer.newDisposable()
val disposable = if (unitTestMode) {
parentDisposable
} else {
// TODO this is a memory leak in the compiler, as this Disposable is not registered and thus is never disposed
// but using parentDisposable as disposable in compiler, causes access to application extension points after
// they was disposed, this needs to be fixed
Disposer.newDisposable("Disposable for the KotlinCoreApplicationEnvironment")
}
ourApplicationEnvironment = createApplicationEnvironment(disposable, configuration, unitTestMode)
ourProjectCount = 0
Disposer.register(disposable, Disposable {