How to empty memory??

Discussion in 'Java' started by mdema@diesel, Jul 16, 2008.

  1. mdema@diesel

    mdema@diesel Guest

    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
     
    mdema@diesel, Jul 16, 2008
    #1
    1. Advertising

  2. mdema@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
     
    RedGrittyBrick, Jul 17, 2008
    #2
    1. Advertising

  3. mdema@diesel

    Daniel Pitts Guest

    RedGrittyBrick wrote:
    > mdema@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/>
     
    Daniel Pitts, Jul 20, 2008
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John

    empty/non-empty element

    John, Jul 15, 2003, in forum: XML
    Replies:
    1
    Views:
    1,039
    Klaus Johannes Rusch
    Jul 16, 2003
  2. Lukas
    Replies:
    3
    Views:
    820
    spiff
    Nov 10, 2005
  3. Marcia Hon

    Check if a directory is empty and empty it

    Marcia Hon, Feb 8, 2004, in forum: C Programming
    Replies:
    8
    Views:
    582
    Dave Thompson
    Feb 14, 2004
  4. Brian Roberts

    empty lists vs empty generators

    Brian Roberts, May 3, 2005, in forum: Python
    Replies:
    12
    Views:
    665
    Jeremy Bowers
    May 4, 2005
  5. ButlerDJIAM
    Replies:
    0
    Views:
    569
    ButlerDJIAM
    Nov 9, 2006
Loading...

Share This Page