Fix memory leak in StdlibTest

This commit is contained in:
Alexander Udalov
2016-04-12 19:56:35 +03:00
parent 11d875ca17
commit 59d73e716c
@@ -47,6 +47,8 @@ import java.io.File;
import java.lang.reflect.Modifier;
public class StdlibTest extends KotlinTestWithEnvironment {
private GeneratedClassLoader classLoader;
@Override
protected KotlinCoreEnvironment createEnvironment() {
CompilerConfiguration configuration = KotlinTestUtils.compilerConfigurationForTests(ConfigurationKind.ALL, TestJdkKind.FULL_JDK);
@@ -68,9 +70,7 @@ public class StdlibTest extends KotlinTestWithEnvironment {
fail("There were compilation errors");
}
GeneratedClassLoader classLoader = new GeneratedClassLoader(
state.getFactory(), ForTestCompileRuntime.runtimeAndReflectJarClassLoader()
) {
classLoader = new GeneratedClassLoader(state.getFactory(), ForTestCompileRuntime.runtimeAndReflectJarClassLoader()) {
@Override
public Class<?> loadClass(@NotNull String name) throws ClassNotFoundException {
if (name.startsWith("junit.") || name.startsWith("org.junit.")) {
@@ -107,6 +107,14 @@ public class StdlibTest extends KotlinTestWithEnvironment {
}
}
@Override
protected void tearDown() throws Exception {
super.tearDown();
// This is important to prevent a memory leak (ClassFileFactory transitively retains all code generation results)
classLoader.dispose();
}
@Nullable
private static Test createTest(@NotNull ClassLoader classLoader, @NotNull String className) {
try {