-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi,
I am observing memory leaks when redeploying my ZK web app in JBoss 5.1.0GA (no Spring). The ZK uses ThreadLocal data extensively, but do not clean them in ServletContextListener.contextDestroyed() and I guess it might be the main source of the problem.
Check similar Spring issue:
http://opensource.atlassian.com/confluence/spring/display/DISC/Memory+leak+-+classloader+won%27t+let+go
Also, the other source of the problem may be commons-logging (maybe SLF4J fixed this problem).
Did somebody else experience memory leaks after redeploy? Is this ZK bug or the problem is somewhere else?
Technically, ZK cleans up each ThreadLocal variable after serving a request. To really know the real cause, we have to use jprofiler or other tools to verify.
Regarding ServletContextListener, we clean up the application when DHtmlLayoutServlet's destroy method is called. It shall have the same effect.
And do you observe memory leaks after redeploy, too?
Hi,
I have used Eclipse MAT and found, that there are some CacheMap objects in the ThreadLocal variables. I suspect the class ThreadLocalCache - it never calls ThreadLocal.remove() method.
Again, I do not see ZK using ThreadLocal.remove() in many other cases, too. So, how and where does ZK clean ThreadLocal variables?
Hi Ondrej,
Could you provide the log of Eclipse MAT? As far as I know we don't have memory leak issue when redeploying on Tomcat. However, I am not sure if the redeployment is going thru Eclipse -- I don't trust Eclipse's memory use. I don't have Eclipse but many of others have to restart Eclipse once a while to clean up.
ZK doesn't call ThreadLocal.remove(). It is supposed to be garbage collected if all classes are unloaded completely (so all references to it are gone)
Hi Tom,
I use JBoss tool in Eclipse to redeploy my web app. This tool just makes a simple file copy. The problem remains also when I redeploy my web app manually. I use exploded deployment. to reproduce the bug, try:
1. copy exploded deployment,
2. run the app (point browses to the proper url)
3. delete the deployment
4. repeat 1. - 3. few times
Maybe the problem is caused by this?
Probem with static ThreadLocal (ZK uses that):
- http://blog.arendsen.net/index.php/2005/02/22/threadlocals-and-memory-leaks-revisited/
- http://www.jroller.com/tackline/entry/fixing_threadlocal
Problem with inner classes and ThreadLocal: http://crazybob.org/2006/02/threadlocal-memory-leak.html
How to clean ThreadLocals in a servlet: http://www.dewavrin.info/?p=196
My heap dump is at:
http://dl.dropbox.com/u/1372480/dump_simple.hprof (206MB, will be deleted later).
I just have started Eclipse MAT and used the function: "Duplicate Classes: Detect classes loaded by multiple class loaders."
Interesting! You're probably right. I'll investigate it a bit more later. Thanks.
I have made a bug for this issue Bug ID 2961772
Thanks. We will follow it there.
@xmedeko
Tom has modified the code lately.
And the issue should be resolved.
Due to some soft reference may not be garbage collected while redeploy,
you may add following setup to jboss vm arguments.
XX:SoftRefLRUPolicyMSPerMB=1
@PeterKuo
I have downloaded the latest ZK 3.6.4 and do not see the Bug ID: 2961772 in the release-notes. Has it been fixed in 3.6.4, too, or just in the 5.0.1?
Thx
Asked: 2009-11-16 07:01:37 +0800
Seen: 3,313 times
Last updated: Mar 24 '10