-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Memory leak when building SessionFactory from xml
PostPosted: Fri Oct 08, 2010 10:23 am 
Newbie

Joined: Fri Oct 08, 2010 9:55 am
Posts: 2
Hi all, I think I detected a classloader memory leak when hibernate loads its configuration from a xml file. I'm not sure if it's and Hibernate problem or a Dom4J problem, but the real thing is that the entire web-application does not get garbage collected.

I reported an issue (HHH-5601), but no response yet.

Bellow the description as reported in the issue, hope you can give a hint.
Description of issue HHH-5601 wrote:
I was able to create a minimum web-application which fails to be garbage collected if session factory uses xml configuration file. This does not happens when it is created programmatically.

The big issue is that in production environment this problem leads to a OutOfMemoryException because of PermGen (because it is needed to restart the context from time to time)

When building session factory from xml, and after starting and then stopping context, I can see all the classes from the webapp using any profiler (jvisualvm, eclipse's memory analyzer, etc). But I could not figure out if the problem is due to how hibernate uses Dom4J or if it is a Dom4J problem. I also switched to many different version of Dom4J but problem still remains.

Here I provide a minimal web application which has only 1 (one) class that creates an empty session factory (this class is a ServletContextListener and is named FDVContextListener) with only a database connection. No mappings at all. The experiment consists in start a Tomcat (maybe 6.0.25+ or 7.x which has the memory leak feature) and later stop the context. Finally, check for leak you'll find webapps classes still there.

2nd part of the experiment is to modify the listener to make it use the programmatic session factory (already provided) and then repeat the start-stop of the context and the memory leak test and confirm that webapp is completly gone.

I repeat again. I'm not sure if it is a Dom4J problem or an Hibernate problem, but I think this is a great opportunity (because of the small test-application) to help find the real problem since hibernate get's affected.

To build the webapp, maven2 is needed and any JDBC database connection (I use oracle-xe)

Hope we can find a solution to this problem.

thank you all.
Juan Manuel


Top
 Profile  
 
 Post subject: Re: Memory leak when building SessionFactory from xml
PostPosted: Fri Oct 08, 2010 10:57 am 
Senior
Senior

Joined: Fri Oct 08, 2010 8:44 am
Posts: 130
The problem is that some containers sometimes are hesitant to garbage collect PermGen space as class unloading normally is a rare operation. I am almost sure that Hibernate has nothing to do with that (except big number of classes used). You may want to tweak your JVM with the following flags:

-XX:+CMSClassUnloadingEnabled -XX:+CMSPermGenSweepingEnabled


Top
 Profile  
 
 Post subject: Re: Memory leak when building SessionFactory from xml
PostPosted: Fri Oct 08, 2010 4:00 pm 
Newbie

Joined: Fri Oct 08, 2010 9:55 am
Posts: 2
Hello "r", thank you very much for taking the time to write.

Don't you think it is weird that when building the SessionFactory programmatically the memory problem does not happen? (the container should not hold any reference to the stuff born in the old class-loader) I think this problem has nothing to do with telling the VM to "also" garbage collect classes on every GC action, because this should be the normal behavior for invalidated class-loaders.

Feel free to try the small experiment proposed above (files are available at the HHH-5601 issue as attachs) and convince yourself of how weird it is!

thank you again for you time.

Juan


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.