Hi,
Problem : After performing query, closing the session, closing the session factory, memory is not released.
I am using lazy collections (3.1.2 has this as a default one for collections).
After performing query -> With lazy collections.
1) (Map) Session.persistenceContext -> Contains the reference of the returned results.
2) On
session.close(), it cllears all the maps in the cleanup() method which is in the final clause of close method. So hibernate clearing all the session data on closing. Still memory is not reclaimed. The proxy objects have reference to session and session->persisitence(Map)->proxy.
Is this a case of circular referenec. I dont think so?.
After Performing query -> Without lazy collections.
This time i changed the
.hbm.xml configuration file so that lazy="false".
1) Perfomed query Memory increased by 5MB. Results have
actual pojo object not proxy. This is a simple case of filling a List with some objects and after the list is out of scope it should be gced.
2) Closed the session. Memory did not come down. I added System.gc() too after closing the session to requeset the gc.
3) Closed the session factory. Memory still did not come down.
Is there any other place, some listener etc, where there are still the references of the pojos returned in the query.
I believe in solving problems myself, but i failed this time. I may be wrong in my testing.
Code:
public static void testHibernateMemory() {
Runtime runtime = Runtime.getRuntime();
System.err.println("Before Session factory");
System.err.println("MAX [" + runtime.maxMemory() + "] Total ["
+ runtime.totalMemory() + "] Free [" + runtime.freeMemory()
+ "]");
SessionFactory sessionFactory = buildSessionFactory();
Session session = sessionFactory.openSession();
Transaction transaction = session.beginTransaction();
System.err.println("After Session factory");
System.err.println("MAX [" + runtime.maxMemory() + "] Total ["
+ runtime.totalMemory() + "] Free [" + runtime.freeMemory()
+ "]");
System.err.println("Thread :" + Thread.currentThread().getName());
try {
System.err.println("-- Before Query ---------------");
List results = findByExampleWithRange(
new Ismmdm(), 0, 5000, new Integer[1],session);
// List results = findByExampleWithRange(new Ismpot(), 0, 50, null);
System.err.println("Total records [" + results.size() + "]");
System.err.println("-- After Query ---------------");
} catch (DAOException e) {
e.printStackTrace();
}
SessionImpl impl = null;
transaction.commit();
System.err.println("-- After Transaction commit ------");
session.close();
session = null;
System.err.println("-- After Session Close ------");
sessionFactory.close();
sessionFactory = null;
System.gc();
System.err.println("-- After Session Factory Close ---------------");
System.err.println("MAX [" + runtime.maxMemory() + "] Total ["
+ runtime.totalMemory() + "] Free [" + runtime.freeMemory()
+ "]");
}
Details about my environment is below.
I am very old user of hibernate. We are successfully using hibernate 2.x version in one of our applications.
Now we are using hibernate 3.x (3.1.2).
------- hibernate.cfg.xml -
<property name="dialect">
org.hibernate.dialect.DB2Dialect
</property>
<property name="hibernate.connection.release_mode">
auto
</property>
<property name="hibernate.current_session_context_class"> thread
</property>
1) Using session per request pattern with ThreadLocalSessionContext. Everything works well functionality wise.
2) Session factory is building code is taken from HibernateUtils.java from CaveatEmptor sample application.
3) Session is created like a caveat emptor application with same web filter.
4) Transaction is committed and session is closed from web filter. Which automatically unbinds the session from ThreadLocal.
5) SessionFactory instance is closed and set to null in Application ContextListener.
I have gone through all the postings related the memory leaks and up to date with all the progress. Aware of all the release notes, eg upgrade cglib to fix memory leak etc.
Even now, i m facing memory leak problem. It grows and end up with out of memory on WAS 5.1. Same is the case on jboss 4.0.2. I have removed the hibernate sar from deploy directoy so that the classes are always loaded from my web application.
Please some one help me.
Help me. Help me.
I think i have the similar problem quite close like you. I have the huge ecomm application where thousands of query perfomed. And after each request, memory grows continously.
Typically, i would expect the memory to increase and them come down once request is processed.
I configured the web application HTTP Thread pool with 10 min and 25 max threads. Pool thread never expires. This helped me to make the application run for longer time but not forever.
Which made me to conclude that processor thread are not releasing memory. And memory is leaked when the thread is dead. (Thread instances not garbase collected).
I am using following jars in my WEB-INF/lib folder :
commons-anm-1.0.0.jar
ism-dist.jar
jstl.jar
lucene-1.4.3.jar
myfaces-extensions.jar
myfaces-impl.jar
myfaces-jsf-api.jar
standard.jar
struts.jar
commons-beanutils.jar
commons-codec-1.2.jar
commons-dbcp-1.1.jar
commons-digester.jar
commons-fileupload.jar
commons-httpclient.jar
commons-lang-1.0.1.jar
commons-pool-1.1.jar
commons-validator.jar
antlr-2.7.6rc1.jar
asm-attrs.jar
asm.jar
cglib-2.1.3.jar
commons-collections-2.1.1.jar
commons-logging-1.0.4.jar
concurrent-1.3.2.jar
dom4j-1.6.1.jar
ehcache-1.1.jar
oscache-2.1.jar
hibernate3.jar (hibernate 3.1.2)
I m ready to produce any other data if needed.
Regards,
-Chandra
_________________
-Chandra Singh (Anmsoft)
Post rating: This posting has not been rated so far.
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelpHibernate version: Mapping documents:Code between sessionFactory.openSession() and session.close():Full stack trace of any exception that occurs:Name and version of the database you are using:The generated SQL (show_sql=true):Debug level Hibernate log excerpt:Code: