how to overcome "java.lang.OutOfMemory" Error

Discussion in 'Java' started by Ananth, Mar 3, 2008.

  1. Ananth

    Ananth Guest

    We already increased the Heap Space, But still i am getting this
    error. Actually we did increase the heapspace upto 1024MB. still java
    process eating memory. After that application crashes. I already
    search so many sites in Google. Can anybody shed some light on this
    issue?
    Ananth, Mar 3, 2008
    #1
    1. Advertising

  2. Ananth, 03.03.2008 13:38:
    > We already increased the Heap Space, But still i am getting this
    > error. Actually we did increase the heapspace upto 1024MB. still java
    > process eating memory. After that application crashes. I already
    > search so many sites in Google. Can anybody shed some light on this
    > issue?


    There are two possible reasons:

    1) you have a memory leak in your program (i.e. objects that are still referenced but no longer needed, so they cannot be garbage collected)

    2) your program simply needs that much memory. Either you algorithm requires to hold that much data in memory, then you are out of luck, or you can rewrite the algorithm (e.g. not reading all 10 million rows from the database table or a 500MB XML file into a DOM tree or whatever you are doing there)

    Thomas
    Thomas Kellerer, Mar 3, 2008
    #2
    1. Advertising

  3. Ananth

    Guest

    Re: how to overcome "java.lang.OutOfMemory" Error

    On Mar 3, 5:58 pm, Thomas Kellerer <> wrote:
    > Ananth, 03.03.2008 13:38:
    >
    > >  We already increased the Heap Space, But still i am getting this
    > > error. Actually we did increase the heapspace upto 1024MB. still java
    > > process eating memory. After that application crashes. I already
    > > search so many sites in Google. Can anybody shed some light on this
    > > issue?

    >
    > There are two possible reasons:
    >
    > 1) you have a memory leak in your program (i.e. objects that are still referenced but no longer needed, so they cannot be garbage collected)
    >
    > 2) your program simply needs that much memory. Either you algorithm requires to hold that much data in memory, then you are out of luck, or you can rewrite the algorithm (e.g. not reading  all 10 million rows from the database table or a 500MB XML file into a DOM tree or whatever you are doing there)
    >
    > Thomas


    Hi
    The simple way to get out of this situation is to follow the following
    give step
    1) Increase the size of Heap Space, as you have already said that you
    had increased the size to 1024MB as per my knowledge it is more than
    enough.
    2) Please look up your code especially by using some external IDE i.e.
    Eclipse, Weblogic IDE this type of tool gives you at the coding level
    only the object which are created but not used in the class, so that
    you can remove.
    3) If possible try to run system.gc() (Not much sure, but still can't
    say anything this might be helpful to you tooo.)
    4) If required please see the performace graph using some tool like,
    JProbe etc which will give you the memory leackage point in your
    application
    Regards
    Siddharatha Dhumale
    , Mar 3, 2008
    #3
  4. Ananth

    Lew Guest

    Re: how to overcome "java.lang.OutOfMemory" Error

    wrote:
    > 3) If possible try to run system.gc() (Not much sure, but still can't
    > say anything this might be helpful to you tooo.)


    This will be useless. Don't bother with System.gc(). (Not "system" -
    spelling counts!)

    Thomas gave you the best advice. A profiler can help identify where the leak is.

    So can really, really rigorous reasoning about the source code. Memory leaks
    in Java come from repeatedly keeping a reference after it isn't needed, such
    as by putting it into a collection like a Map. The solution is to use
    "temporary" variables that go out of scope (the block ends) as the only
    references to such objects. Avoid static and collection references to objects
    that need to go away.

    If your algorithm simply demands gigabytes (or gibibytes) of data, either you
    are going to have to stripe the algorithm or buy more RAM.

    --
    Lew
    Lew, Mar 3, 2008
    #4
  5. Ananth

    Roedy Green Guest

    On Mon, 3 Mar 2008 04:38:14 -0800 (PST), Ananth <>
    wrote, quoted or indirectly quoted someone who said :

    > We already increased the Heap Space, But still i am getting this
    >error. Actually we did increase the heapspace upto 1024MB. still java
    >process eating memory. After that application crashes. I already
    >search so many sites in Google. Can anybody shed some light on this
    >issue?


    see http://mindprod.com/jgloss/packratting.html
    http://mindprod.com/jgloss/profiler.html
    --

    Roedy Green Canadian Mind Products
    The Java Glossary
    http://mindprod.com
    Roedy Green, Mar 3, 2008
    #5
  6. Ananth

    Jason Cavett Guest

    Re: how to overcome "java.lang.OutOfMemory" Error

    On Mar 3, 6:16 pm, Roedy Green <>
    wrote:
    > On Mon, 3 Mar 2008 04:38:14 -0800 (PST), Ananth <>
    > wrote, quoted or indirectly quoted someone who said :
    >
    > > We already increased the Heap Space, But still i am getting this
    > >error. Actually we did increase the heapspace upto 1024MB. still java
    > >process eating memory. After that application crashes. I already
    > >search so many sites in Google. Can anybody shed some light on this
    > >issue?

    >
    > seehttp://mindprod.com/jgloss/packratting.htmlhttp://mindprod.com/jgloss/profiler.html
    > --
    >
    > Roedy Green Canadian Mind Products
    > The Java Glossaryhttp://mindprod.com


    Good articles. Thank you very much. Appreciate it.
    Jason Cavett, Mar 4, 2008
    #6
  7. Ananth

    Jason Cavett Guest

    Re: how to overcome "java.lang.OutOfMemory" Error

    On Mar 3, 6:16 pm, Roedy Green <>
    wrote:
    > On Mon, 3 Mar 2008 04:38:14 -0800 (PST), Ananth <>
    > wrote, quoted or indirectly quoted someone who said :
    >
    > > We already increased the Heap Space, But still i am getting this
    > >error. Actually we did increase the heapspace upto 1024MB. still java
    > >process eating memory. After that application crashes. I already
    > >search so many sites in Google. Can anybody shed some light on this
    > >issue?

    >
    > seehttp://mindprod.com/jgloss/packratting.htmlhttp://mindprod.com/jgloss/profiler.html
    > --
    >
    > Roedy Green Canadian Mind Products
    > The Java Glossaryhttp://mindprod.com


    So, I'm curious because I noticed you said that Images need to be
    flushed. What happens in the case when an Image is not actually
    created, but only set...such as...

    someObject.setImage(anImageIcon.getImage());

    How is that handled? Should I be handling it?


    Very informative site, BTW. Thank you for the link.
    Jason Cavett, Mar 4, 2008
    #7
  8. Ananth

    Roedy Green Guest

    Re: how to overcome "java.lang.OutOfMemory" Error

    On Tue, 4 Mar 2008 11:40:35 -0800 (PST), Jason Cavett
    <> wrote, quoted or indirectly quoted someone
    who said :

    >someObject.setImage(anImageIcon.getImage());

    what type is someObject. There is no method Object.setImage.

    Presumably when you were done with the image you might
    getImage().flush().

    The images I work with tend to get loaded when the program starts and
    hang around till it terminates.
    --

    Roedy Green Canadian Mind Products
    The Java Glossary
    http://mindprod.com
    Roedy Green, Mar 5, 2008
    #8
  9. Ananth

    Jason Cavett Guest

    Re: how to overcome "java.lang.OutOfMemory" Error

    On Mar 5, 3:05 am, Roedy Green <>
    wrote:
    > On Tue, 4 Mar 2008 11:40:35 -0800 (PST), Jason Cavett
    > <> wrote, quoted or indirectly quoted someone
    > who said :
    >
    > >someObject.setImage(anImageIcon.getImage());

    >
    > what type is someObject. There is no method Object.setImage.
    >
    > Presumably when you were done with the image you might
    > getImage().flush().
    >
    > The images I work with tend to get loaded when the program starts and
    > hang around till it terminates.
    > --
    >
    > Roedy Green Canadian Mind Products
    > The Java Glossaryhttp://mindprod.com


    someObject is a TreeCellEditor. I set the image on the TreeCellEditor
    so I can set icons on the JTree.

    What I was thinking is that I may not need to flush due to the fact
    that, when the TreeCellEditor is destroyed, it'll lose the references
    to the image (since no other references are held anywhere).
    Jason Cavett, Mar 5, 2008
    #9
    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. Michael Borgwardt

    java.lang.OutOfMemory

    Michael Borgwardt, May 7, 2004, in forum: Java
    Replies:
    8
    Views:
    3,523
    Boudewijn Dijkstra
    May 15, 2004
  2. Rune
    Replies:
    2
    Views:
    537
    Kevin McMurtrie
    Feb 19, 2005
  3. Replies:
    25
    Views:
    9,477
  4. Rajesh.Rapaka

    Busting "java.lang.outofmemory"

    Rajesh.Rapaka, Jul 13, 2005, in forum: Java
    Replies:
    17
    Views:
    922
    Martin Jost
    Jul 27, 2005
  5. Guest
    Replies:
    1
    Views:
    471
    Florian Diesch
    Jun 12, 2005
Loading...

Share This Page