This is the mail archive of the
java@gcc.gnu.org
mailing list for the Java project.
Unloading classes
- From: Anthony Green <green at redhat dot com>
- To: java at gcc dot gnu dot org
- Date: 03 Nov 2002 15:36:58 -0800
- Subject: Unloading classes
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