• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Unloading a class from JVM..????

 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi all
is it possible to unload a class which is loaded in JVM, I mean dynamic reloading of a class only when its necessary instead of keeping it loaded all the time

thx
harish
 
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, BUT, the only way to do this is to dispose of the class loader that was used to load the classes.
You have to create a custom class loader, and early in your loading process, use your class loader to load the classes you might wish to later unload. When you dispose of the class loader, all the classes loaded by it are also disposed. Then you can create a new class loader and reload those classes, thus getting the effect of dynamic loading.
 
Ranch Hand
Posts: 1209
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Rob Ross:

You have to create a custom class loader, and early in your loading process, use your class loader to load the classes you might wish to later unload. When you dispose of the class loader, all the classes loaded by it are also disposed. Then you can create a new class loader and reload those classes, thus getting the effect of dynamic loading.


Ok i have a doubt. Say i have a custom classloader which loads the first version of a class. As usual i assign the loaded class instance to an interface handle.
Then i try loading the changed version of the class through another Custom Class loader instance.
Now even if i explicitly set the earlier class loader to null, will the first version of the class really unload? since i'm holding to an instance of that class?
My guess is that in that case 2 versions of the class will reside in the JVM.
can anyone confirm this?
thanks!
reply
    Bookmark Topic Watch Topic
  • New Topic