File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Tomcat and the fly likes tomcat leak :static class variables Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "tomcat leak :static class variables" Watch "tomcat leak :static class variables" New topic

tomcat leak :static class variables

amir taghvayi
Ranch Hand

Joined: Sep 16, 2011
Posts: 54

i read this article:
The article was written:
When an app is stopped, Tomcat (even before 6.0.24) nullifies the value of all static class variables of classes loaded by the WebAppClassLoader. In some cases, it may fix a classloader leak (for example because of a custom ThreadLocal class, see above), but even if we still have a leak, it may decrease the amount of memory lost:

Imagine a class with the following variable :

private final static byte[] BUFFER = new byte[1024*1024]; //1MB buffer

Normally, the 1MB buffer should be freed when the app is stopped, but only if the classloader itself can be garbage-collected. Since there are still possibilities to have a leak of the classloader, clearing the BUFFER variable allows to recover 1MB of memory.

We do not use the staticClassVariables ?
What can be used instead of staticClassVariables?

please help me .
ali farozi

Joined: May 23, 2012
Posts: 6
The workaround described in the article was created to deal with the unique problem of reloadable classloaders and static class variables. If you are using regular, non-static variables then the 'porblem' doesnt apply to you, as the regular garbage collection mechanism will handle those variables just fine.
I agree. Here's the link:
subject: tomcat leak :static class variables
It's not a secret anymore!