Everytime I re-deploy my application, the JVM Perm Memory will increase
about 4.5MB, it's never reclaimed by the JVM, and at end I have to restart
my application server.
I have followed up and researched this issue quite a while. I read the
Hivemind code around Thread Cleanup; I also read the source code of
java.lang.ThreadLocal. Here are my findings (theoretically, not verified in
practice):
I think that the ThreadLocals are causing the Perm memory leak.
In the Hivemind ThreadedServiceModel, the ThreadLocal's content is set to
null when doing thread cleanup. But this does not remove the ThreadLocal
variable from the thread's local map. The ThreadLocal will never be
released. This will prevent the ear class loader from being
garbage-collected. In JDK5.0, a new method is added into ThreadLocal class:
remove; which will truely remove the ThreadLocal variable from the thread's
local map.
Could Tapestry/Hivemind developers (may be Howard) verify my investigation
and make a Hivemind build for JDK5.0 to remove the memory leak? It's just
one line change in ThreadedServiceModel.java:
private void unbindServiceFromCurrentThread()
{
_activeService.set(null); // change to _activeService.remove();
}
Any thoughts?
Thanks.
Best Regards,
Cliff Zhao