Coder's Guild Mailing List

Re: Class loading and Unloading

Posted by Benjamin Johnston on 2000-06-25

> Is it possible for me to unload a class from my java program and the VM
release the memory that was associated with that class?

I'm not that knowledgeable in this area, but I remember hearing that some
newer VM's will automatically garbage collect unused class files.

But just like Object garbage collection, you can't depend on this.

> Also these classes could be subject to change while the program is still
running. Would the new version of the class be loaded in or would the old
version still remain in memory?

I don't think this is possible, because you'd have a "collision" in the name
space. I would have thought this would only have been possible by creating a
new classloader... Mark Horan's post suggested otherwise, so I may be wrong
though.

You could write your own classloader, to effectively create a new namespace.

Again, I'm not very familiar with this technology, but take a look at
java.lang.ClassLoader -- it may be what you have in mind.

-Benjamin Johnston
s355171@xxxxxxx.xx.xxx.xx