how to overcome "java.lang.OutOfMemory" Error

A

Ananth

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?
 
T

Thomas Kellerer

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
 
S

siddharathadhumale

Ananth, 03.03.2008 13:38:


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
 
L

Lew

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.
 
J

Jason Cavett

seehttp://mindprod.com/jgloss/packratting.htmlhttp://mindprod.com/jgloss/profiler.html

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.
 
R

Roedy Green

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.
 
J

Jason Cavett

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.

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).
 

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
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top