JavaMemoryModel: When can a classloader be unloaded

From: Bill Pugh (
Date: Wed May 19 2004 - 15:11:50 EDT

Say you have a class:

abstract class PrintStuff {
   public static void print() throws InterruptedException {
                while (true) {

And then you create a classloader that loads this class, and then
reflection, invokes the print() method. No other class is loaded by
that classloader.

Will the fact that a thread is running in a static method of a class
mean that the class is reachable, and therefore the classloader is
as well?

Obviously (we think), if there are any active uses of an instance of a
class X,
then the class is reachable.

But we couldn't absolutely convince ourselves that running a static
of a class ensures the class is reachable.

(By the way, section 12.7 of the JLS (2nd edition) says "A class or
interface may
be unloaded if and only if its defining class loader may be reclaimed
by the
garbage collector as discussed in 12.6." But it isn't discussed there.


JavaMemoryModel mailing list -

This archive was generated by hypermail 2b29 : Thu Oct 13 2005 - 07:01:07 EDT