Maybe a useful URL to help address this matter when it bites, look for the java code in the forum thread: http://forum.hibernate.org/viewtopic.php?t=935948&start=150

Something to put at the end of your javax.servlet.ServletContextListener#contextDestroyed(ServletContextEvent).


Abstracting your Singletons behind something else (maybe something as saft as Map) which has simple lifecycle management hooks on all contained objects would allow during context undeploy for the shutdown to be called on the lifecycle.

Even I am not that zealous with caution to implement and use it for everyday code.


The same problem can exist for ThreadLocal data (which a common pattern hibernate uses), if you don't gaurd your code usage so that as you cleanup from the servlet/filter you null out the ThreadLocal you may have setup.

Darryl


Peter Crowther wrote:
From: Leon Rosenberg [mailto:[EMAIL PROTECTED] Could you explain it a bit more? What's the difference whether I have
10 instances of the same class or just one for reloading?

In a Singleton:

- the class holds a reference to the classloader;

- the class holds a reference to the singleton instance;

- the instance holds a reference to the class.

My understanding is that classes cannot be GCed unless they have no
instances, and classloaders are (obviously) not collected until they
have no references from classes.  So singletons leave classes lying
around in your JVM.  More annoyingly, classes always occupy PermGen
space, so this junk class is now eating up precious space in PermGen -
hence the possibility of an OOME if you reload your webapp too many
times.  The solution is to implement appropriate listeners to make sure
the instance is not referenced by the class before the webapp is
unloaded.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to