• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Scott Selikoff
Bartenders:
  • Piet Souris
  • Jj Roberts
  • fred rosenberger

Unloading a class dynamically

 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Friends,
How can I unload a class, during the course of execution of a program ?
Thanks,
Gopal.
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If it is loaded by the bootstrap classloader, you can not.
For other classes remember

A class or interface may be unloaded if and only if its class loader is unreachable. Classes loaded by the bootstrap loader may not be unloaded.


from Clarifications and Amendments to The Java Language Specification.
 
Gopal Shah
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Cindy,
I went thru the link and there it is mentioned

it follows that one must not unload a class while its loader is still reachable.

.
1. So can a user unload a class himself (r there any methods to unload a class) ?

However, if a class is unloaded while its loader is reachable, it may be reloaded


2. Does it mean classes are loaded and reloaded by JVM at its own whim for optimization. Basically I wanted to cater to the problem of
Static variables losing its state when classes r reloaded. When should I provide explicit code to ensure that state is not lost ?
 
author and iconoclast
Posts: 24204
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What gave you the idea that this was a problem? The ClassLoader architecture changed quite a bit for Java 2, and problems of this type described early in Java's history are simply no longer a problem. Are you worrying about a problem you've never seen?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic