|
Prev: Impostor posts
Next: how to run applet .java file
From: mdema on 16 Jul 2008 10:33 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
From: RedGrittyBrick on 17 Jul 2008 05:26 mdema(a)diesel wrote: > 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. -- RGB
From: Daniel Pitts on 19 Jul 2008 19:34 RedGrittyBrick wrote: > mdema(a)diesel wrote: >> 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. > 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. -- Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>
|
Pages: 1 Prev: Impostor posts Next: how to run applet .java file |