Unloading classes
Anthony Green
green@redhat.com
Sun Nov 3 16:37:00 GMT 2002
I recently noticed that we don't unload interpreted classes properly.
The following test program loops around, dynamically creating a class
loader and class on each iteration. The heap should, in theory, stop
growing at some point - but it doesn't.
---- cut here -------------------------------------
import java.net.*;
import java.lang.reflect.*;
public class TestLeak
{
class MyLoader extends URLClassLoader
{
public MyLoader (URL urls[])
{
super (urls);
}
}
public static void main (String[] args)
{
URLClassLoader ucl =
(URLClassLoader) ClassLoader.getSystemClassLoader();
URL urls[] = ucl.getURLs ();
Class ifaces[] = new Class[1];
ifaces[0] = java.lang.Comparable.class;
try {
for (int i = 0; i < 10000; i++)
{
Proxy.getProxyClass (new MyLoader (urls), ifaces);
}
} catch (Exception e) {
e.printStackTrace ();
}
}
}
---- cut here -------------------------------------
I believe the problem is with initiated_classes and loaded_classes, in
natClassLoader.cc. It seems like we'll have to do some of the same tricks
we pull in natReference.c in order to turn these into "weak" reference data
structures (and eliminate Class.next). Any other ideas?
AG
More information about the Java
mailing list