[kaffe] Kaffe CVS: kaffe hkraemer

Helmer Krämer hkraemer at freenet.de
Mon May 19 15:06:01 PDT 2003


On Mon, 19 May 2003 14:20:51 -0700 (PDT)
Dalibor Topic <robilad at yahoo.com> wrote:

Hallo Dalibor,

> If I understand that correctly, the main problem is that
> * a ClassLoader stores all loaded Classes in a HashMap
> * since a ClassLoader is stored in its own class loader's HashMap, it is always
> strongly reachable.
> * so it can never be unloaded.

yep.

> I believe that's a problem built for WeakHashMaps ;) So I'll try to create a
> patch that stores ClassLoaders separately in a WeakHashMap and see if that
> helps.

Wasn't there some problem with gc'ing classes and the
singleton design pattern? That is if you have something
like this:

public class Foo {
	private static Foo instance;

	public static Foo get() {
		if (instance == null) {
			instance = new Foo();
		}
		return instance;
	}
}

You can easily get the situation that Foo is only referenced by
itself, in which case it would be subject for gc (if we used
a WeakHashMap). Gc'ing singletons however isn't a very good idea.

Strongly referencing a class from the classloader that loaded it
solves this problem, since a class can then only be gc'ed if its
defining classloader can be gc'ed, which means that nobody is able
to access the singleton anyway. This in turn would mean that the
test in its current form is wrong, the failure is a correct result
and we should fix the test case and should better leave the rest
of the vm untouched...

Greetings,
Helmer




More information about the kaffe mailing list