How to empty memory??

M

mdema@diesel

Hi,
I have a JTable which is filled up by a List<Book> (Book is an Entity
class).
The filling itself is made by:

listBooks = query.getResultList();
updateTable(listBooks);


where "query" is a Query object of JPA.
My problem is that, after making a search in the DB, I think that memory
is not freed, because, for example, if I make a search with no
parameters (which returns me more or less 20000 records), the first time
it works while the seconds JVM throws java.lang.OutOfMemoryError: Java
heap space.
I wanted to know how could I "free" all the memory after I updated the
JTable...
Thank you very much.
Bye
 
R

RedGrittyBrick

mdema@diesel said:
Hi,
I have a JTable which is filled up by a List<Book> (Book is an Entity
class).
The filling itself is made by:

listBooks = query.getResultList();
updateTable(listBooks);


where "query" is a Query object of JPA.
My problem is that, after making a search in the DB, I think that memory
is not freed, because, for example, if I make a search with no
parameters (which returns me more or less 20000 records), the first time
it works while the seconds JVM throws java.lang.OutOfMemoryError: Java
heap space.
I wanted to know how could I "free" all the memory after I updated the
JTable...

By making the memory-consuming object(s) eligible for garbage
collection. Normally this is done by arranging that references go out of
scope.

I'd read the following and apply the guidance they give.

http://mindprod.com/jgloss/packratting.html
http://mindprod.com/jgloss/garbagecollection.html
http://sscce.org/

Caveat: I am not familiar with JPA. In your shoes I'd also scrutinise
the JPA documentation for any hints about GC or memory usage. Not that
I'd expect to find anything.
 
D

Daniel Pitts

RedGrittyBrick said:
By making the memory-consuming object(s) eligible for garbage
collection. Normally this is done by arranging that references go out of
scope.

I'd read the following and apply the guidance they give.

http://mindprod.com/jgloss/packratting.html
http://mindprod.com/jgloss/garbagecollection.html
http://sscce.org/

Caveat: I am not familiar with JPA. In your shoes I'd also scrutinise
the JPA documentation for any hints about GC or memory usage. Not that
I'd expect to find anything.
My experience is with Hibernate, but I suspect this advice may be related:

Entity classes returned by a query are generally attached to a Session
object (for dirty checking and caching purposes). I believe there is a
way to detach entities from the session, which will allow them to be
reclaimed by the garbage collector.

Another thing to try, is to increase the amount of memory available to
the JVM. It could be that your code is fine, but that it just takes a
little more memory than the JVM has. You can Google for Java Heap size.

Hope this helps,
Daniel.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,270
Latest member
TopCryptoTwitterChannels_

Latest Threads

Top