Skip to content

Commit 59d73e7

Browse files
committed
Fix memory leak in StdlibTest
1 parent 11d875c commit 59d73e7

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

compiler/tests/org/jetbrains/kotlin/codegen/StdlibTest.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747
import java.lang.reflect.Modifier;
4848

4949
public class StdlibTest extends KotlinTestWithEnvironment {
50+
private GeneratedClassLoader classLoader;
51+
5052
@Override
5153
protected KotlinCoreEnvironment createEnvironment() {
5254
CompilerConfiguration configuration = KotlinTestUtils.compilerConfigurationForTests(ConfigurationKind.ALL, TestJdkKind.FULL_JDK);
@@ -68,9 +70,7 @@ public void testStdlib() throws ClassNotFoundException {
6870
fail("There were compilation errors");
6971
}
7072

71-
GeneratedClassLoader classLoader = new GeneratedClassLoader(
72-
state.getFactory(), ForTestCompileRuntime.runtimeAndReflectJarClassLoader()
73-
) {
73+
classLoader = new GeneratedClassLoader(state.getFactory(), ForTestCompileRuntime.runtimeAndReflectJarClassLoader()) {
7474
@Override
7575
public Class<?> loadClass(@NotNull String name) throws ClassNotFoundException {
7676
if (name.startsWith("junit.") || name.startsWith("org.junit.")) {
@@ -107,6 +107,14 @@ public Class<?> loadClass(@NotNull String name) throws ClassNotFoundException {
107107
}
108108
}
109109

110+
@Override
111+
protected void tearDown() throws Exception {
112+
super.tearDown();
113+
114+
// This is important to prevent a memory leak (ClassFileFactory transitively retains all code generation results)
115+
classLoader.dispose();
116+
}
117+
110118
@Nullable
111119
private static Test createTest(@NotNull ClassLoader classLoader, @NotNull String className) {
112120
try {

0 commit comments

Comments
 (0)