The Artima Developer Community
Sponsored Link

Unloading and Reloading Types

Advertisement

Advertisement

This page contains an archived post to the Design Forum (formerly called the Flexible Java Forum) made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

Unloading and Reloading Types

Posted by Bill Venners on 22 Dec 1998, 7:47 PM

> I've been trying to write a class loader which allows me to 'reload'
> classes on request without any luck so far.

> What makes them get ditched?

> Any chance of more detail on how 'Live replacement' would work?
> I saw something about problems with the CLASSPATH in previous messages?

A class loader and the types it has loaded can be unloaded
if there are no more references to any of it from anywhere in
else in the program. So to make the classes loaded into a name
space available for garbage collection, you must just free up
all references to the class loader, to any instances of classes
loaded by that class loader, and to any java.lang.Class
instances representing types loaded into that name space.

To "reload" classes, however, you don't really need to ditch
the already loaded classes -- just create a new name space and
load the classes into that. Once a type is loaded into a name
space, it can be unloaded, but it can't be replaced. To "reload"
a type, you must create a fresh name space and load stuff into
that name space, then use that name space instead of the
previously existing one. So just create a new class loader and
load the stuff again, and you'll have accomplished your
reloading. Release all references to the old name space, and
you'll make that stuff available for GC.

bv



Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us