jQuery in Action, 3rd edition
The moose likes Java in General and the fly likes Class Unloading Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Class Unloading" Watch "Class Unloading" New topic

Class Unloading

Shanmuga Raja

Joined: Jun 14, 2004
Posts: 16
How to unload the classes in java?

Lin Feng
Ranch Hand

Joined: Dec 11, 2002
Posts: 142
Recreate your class loader?
Ulas Ergin
Ranch Hand

Joined: Oct 10, 2002
Posts: 77
A Classloader is garbage collected when none of the classes loaded by it is used anymore.And when the classloader is gone,your class is 'unloaded'.

So try creating another classloader and begin loading your classed with it,
derefer the classed loaded by the previous loader and you're done.
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
It gets a little spooky. This code is just typed ... not compiled or tested but I think the basic idea is sound:

Thing one (for cat in hat fans) will be loaded by the default class loader. Thing two will be loaded by a new class loader. If the file thing.class on disk changed since it was first referenced by the default class loader, they might have different versions of the class. That could lead to some very puzzling bugs!

It is done, tho. The JSP container recompiles and reloads JSPs if they have changed on disk. JUnit has an option to load the class under test every time it runs. Some debuggers can reload classes without stopping and restarting a program. But be careful!

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
I agree. Here's the link: http://aspose.com/file-tools
subject: Class Unloading
jQuery in Action, 3rd edition