Fix memory leak in StdlibTest
This commit is contained in:
@@ -47,6 +47,8 @@ import java.io.File;
|
|||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
|
|
||||||
public class StdlibTest extends KotlinTestWithEnvironment {
|
public class StdlibTest extends KotlinTestWithEnvironment {
|
||||||
|
private GeneratedClassLoader classLoader;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected KotlinCoreEnvironment createEnvironment() {
|
protected KotlinCoreEnvironment createEnvironment() {
|
||||||
CompilerConfiguration configuration = KotlinTestUtils.compilerConfigurationForTests(ConfigurationKind.ALL, TestJdkKind.FULL_JDK);
|
CompilerConfiguration configuration = KotlinTestUtils.compilerConfigurationForTests(ConfigurationKind.ALL, TestJdkKind.FULL_JDK);
|
||||||
@@ -68,9 +70,7 @@ public class StdlibTest extends KotlinTestWithEnvironment {
|
|||||||
fail("There were compilation errors");
|
fail("There were compilation errors");
|
||||||
}
|
}
|
||||||
|
|
||||||
GeneratedClassLoader classLoader = new GeneratedClassLoader(
|
classLoader = new GeneratedClassLoader(state.getFactory(), ForTestCompileRuntime.runtimeAndReflectJarClassLoader()) {
|
||||||
state.getFactory(), ForTestCompileRuntime.runtimeAndReflectJarClassLoader()
|
|
||||||
) {
|
|
||||||
@Override
|
@Override
|
||||||
public Class<?> loadClass(@NotNull String name) throws ClassNotFoundException {
|
public Class<?> loadClass(@NotNull String name) throws ClassNotFoundException {
|
||||||
if (name.startsWith("junit.") || name.startsWith("org.junit.")) {
|
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
|
@Nullable
|
||||||
private static Test createTest(@NotNull ClassLoader classLoader, @NotNull String className) {
|
private static Test createTest(@NotNull ClassLoader classLoader, @NotNull String className) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user