diff --git a/core/reflection.jvm/src/kotlin/reflect/jvm/internal/KCallableContainerImpl.kt b/core/reflection.jvm/src/kotlin/reflect/jvm/internal/KCallableContainerImpl.kt index c35c62f08f6..52ad25aa4d3 100644 --- a/core/reflection.jvm/src/kotlin/reflect/jvm/internal/KCallableContainerImpl.kt +++ b/core/reflection.jvm/src/kotlin/reflect/jvm/internal/KCallableContainerImpl.kt @@ -33,6 +33,11 @@ import java.lang.reflect.Method import kotlin.reflect.KotlinReflectionInternalError abstract class KCallableContainerImpl { + // Note: this is stored here on a soft reference to prevent GC from destroying the weak reference to it in the moduleByClassLoader cache + val moduleData by ReflectProperties.lazySoft { + jClass.getOrCreateModule() + } + abstract val jClass: Class<*> abstract val scope: JetScope diff --git a/core/reflection.jvm/src/kotlin/reflect/jvm/internal/KClassImpl.kt b/core/reflection.jvm/src/kotlin/reflect/jvm/internal/KClassImpl.kt index 6af91c90280..6d1a44a6d44 100644 --- a/core/reflection.jvm/src/kotlin/reflect/jvm/internal/KClassImpl.kt +++ b/core/reflection.jvm/src/kotlin/reflect/jvm/internal/KClassImpl.kt @@ -28,7 +28,6 @@ class KClassImpl(override val jClass: Class) : KCallableContainerImpl(), K // resulting in infinite recursion val descriptor by ReflectProperties.lazySoft { - val moduleData = jClass.getOrCreateModule() val classId = classId val descriptor =