In SKIE Gradle tests that use Gradle TestKit, we n...
# gradle
t
In SKIE Gradle tests that use Gradle TestKit, we noticed a memory leak when the same Gradle daemon is used with multiple versions of KGP. We expect that only happens when using Kotlin Multiplatform. The leak seems to originate from
KotlinToolRunner
and it's companion object's property
isolatedClassLoadersMap
. Kotlin/Native uses
KotlinToolRunner
to create a new
URLClassLoader
with the
kotlin-native-compiler-embeddable.jar
file. When multiple Gradle builds reuse the same Gradle daemon, but use different Kotlin versions, the
kotlin-native-compiler-embeddable.jar
is loaded to memory for each of those. From our testing it's about 8 thousand classes per each and quickly leads to consuming all of metaspace. For some reason it doesn't get garbage collected and stays in the Gradle daemon's memory. Is this an expected behavior where Kotlin/Native essentially "caches" these classes in the daemon, or is the expectation these would be deallocated?
👀 1
t
Is this an expected behavior where Kotlin/Native essentially "caches" these classes in the daemon
Yes, the idea is to keep these classes between builds to improve performance. We are redoing this part in the 2.0.20 release, though please open a Kotlin issue for this.
So while it is not directly related to original question, this issue should be relevant starting 2.0.20 release