0

Redeploy memory leaks

asked 2009-11-16 07:01:37 +0800

xmedeko gravatar image xmedeko
1021 1 16
http://xmedeko.blogspot.c...

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?

delete flag offensive retag edit

22 Replies

Sort by ยป oldest newest

answered 2009-11-16 19:55:34 +0800

tomyeh gravatar image tomyeh
610 1 3
http://blog.zkoss.org ZK Team

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.

link publish delete flag offensive edit

answered 2009-11-17 11:11:07 +0800

xmedeko gravatar image xmedeko
1021 1 16
http://xmedeko.blogspot.c...

And do you observe memory leaks after redeploy, too?

link publish delete flag offensive edit

answered 2010-01-21 08:35:51 +0800

xmedeko gravatar image xmedeko
1021 1 16
http://xmedeko.blogspot.c...

updated 2010-01-21 09:28:49 +0800

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?

link publish delete flag offensive edit

answered 2010-01-21 18:56:55 +0800

tomyeh gravatar image tomyeh
610 1 3
http://blog.zkoss.org ZK Team

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)

link publish delete flag offensive edit

answered 2010-01-22 02:30:44 +0800

xmedeko gravatar image xmedeko
1021 1 16
http://xmedeko.blogspot.c...

updated 2010-01-22 03:53:05 +0800

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."

link publish delete flag offensive edit

answered 2010-01-22 05:29:28 +0800

tomyeh gravatar image tomyeh
610 1 3
http://blog.zkoss.org ZK Team

Interesting! You're probably right. I'll investigate it a bit more later. Thanks.

link publish delete flag offensive edit

answered 2010-03-02 02:43:52 +0800

xmedeko gravatar image xmedeko
1021 1 16
http://xmedeko.blogspot.c...

I have made a bug for this issue Bug ID 2961772

link publish delete flag offensive edit

answered 2010-03-02 04:38:51 +0800

tomyeh gravatar image tomyeh
610 1 3
http://blog.zkoss.org ZK Team

Thanks. We will follow it there.

link publish delete flag offensive edit

answered 2010-03-15 01:27:42 +0800

PeterKuo gravatar image PeterKuo
481 2

@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

link publish delete flag offensive edit

answered 2010-03-16 03:29:47 +0800

xmedeko gravatar image xmedeko
1021 1 16
http://xmedeko.blogspot.c...

@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

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2009-11-16 07:01:37 +0800

Seen: 3,313 times

Last updated: Mar 24 '10

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More