-->
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.  [ 6 posts ] 
Author Message
 Post subject: Remove the loaded object from memory!
PostPosted: Tue Jul 27, 2004 10:12 am 
Regular
Regular

Joined: Sun Jan 18, 2004 9:43 am
Posts: 50
Hi all

I need to make a query that retrieve a large amount of records. I would like to know
how to minimise the memory footprint. I retrieved the data like the following.

Query query = session.createQuery("from account");
Iterator it = query.iterate();

while (it.hasNext()) {
Object o = it.next();
// ...
// ... use the object
// ...
session.evict(o);
it.remove();
}

When I run the program, the memory it uses keep growing and doesn't seem to release the memory of the object after use and eventually the program terminated with a OutOfMemoryError.

I tried removing the session.evict(o) and it.remove(), however the memory usage of the program is still the same.

How can the memory be released?

Thank in advance!!

Edmond

_________________
Edmond Hung
Credit Card DNA Security System (Holdings) Ltd.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 27, 2004 10:37 am 
Expert
Expert

Joined: Fri Feb 06, 2004 7:49 am
Posts: 255
Location: Moscow, Russia
I don't know if Session.evict is cascade, that is if it evicts all dependent objects. But you can use Session.clear()


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 27, 2004 10:55 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Session.evict() cascades to associations if they are mapped with cascade="all" or cascade="all-delete-orphan".

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 27, 2004 11:17 am 
Expert
Expert

Joined: Fri Feb 06, 2004 7:49 am
Posts: 255
Location: Moscow, Russia
christian wrote:
Session.evict() cascades to associations if they are mapped with cascade="all" or cascade="all-delete-orphan".

I think it should be added to the Session.evict javadoc :)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 28, 2004 12:59 am 
Regular
Regular

Joined: Sun Jan 18, 2004 9:43 am
Posts: 50
shl wrote:
I don't know if Session.evict is cascade, that is if it evicts all dependent objects. But you can use Session.clear()



However, it throws OutOfMemoryError after getting almost the same amount of records no matter the Session.evict has been called or not. Therefore, I wonder if the object is still living in the iterator (or Collection), so even I called the evict there is still a reference of the object in the iterator (or Collection).


So, it can be solved??

_________________
Edmond Hung
Credit Card DNA Security System (Holdings) Ltd.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 28, 2004 2:48 am 
Expert
Expert

Joined: Fri Feb 06, 2004 7:49 am
Posts: 255
Location: Moscow, Russia
Instead of Session.evict() use Session.clear(). Session.evict(obj) removes obj object and all its dependent ones mapped with cascade="all" and "all-delete-orphan". So if you have dirty objects in the Session cache, use:
Code:
session.flush(); // flush changes into database
session.clear(); // full clean-up of session cache

else use only session.clear()

And add -Xms128m -Xmx512m to JVM options of your application server or Servlet/JSP container.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.