Hibernate version: 2.1.2
Name and version of the database you are using:MySQL 4.1.5
The generated SQL (show_sql=true):true
Hi I have a simple JUnit test that loops forever calling the specified method:
Code:
public void testIt() throws Throwable {
try {
long count = 0;
while (true) {
runHibernateQuery();
Thread.sleep(1L);
System.out.println("*** LOOP: " + (++count));
}
} catch (Throwable t) {
t.printStackTrace();
throw t;
}
}
protected void runHibernateQuery() throws Exception {
if (sessionFactory == null) {
sessionFactory = createSessionFactory();
}
Session session = sessionFactory.openSession();
net.sf.hibernate.Transaction tx = null;
try {
tx = session.beginTransaction();
net.sf.hibernate.Query query = session.createQuery("FROM MyTable");
Iterator iterator = query.iterate();
while (iterator.hasNext()) {
Object object = iterator.next();
System.out.println(">>> Got Object: " + object);
session.evict(object);
}
if (iterator instanceof HibernateIterator) {
// I know, probably don't need to do this but trying anything here.
((HibernateIterator) iterator).close();
}
tx.commit();
} catch (Exception e) {
if (tx != null) {
tx.rollback();
}
throw e;
} finally {
session.close();
}
}
I create the SessionFactory once using default hibernate properties. The test runs for ONLY 1500 iterations then I get an OutOfMemoryError. I'm running with the Java memory profiler on and the memory usage steadily increases. I'm also using the default initial and maximum memory sizes (64 megs I assume). Under real conditions we have these settings larger but in this simple test why should running the same query over and over with closing the session each time increase the memory?
I'm not sure where the problem lies. I am aware that (from searching this forum) that its highly unlikely its a hibernate problem but I really can't make the test more simple than this. The only possible alternative could be a MySQL leak I guess maybe with not closing connections but if I'm closing the hibernate session each time shouldn't that close the underlying DB connection?
Thanks for any help!
Mike