0

Hi

I got runtime error as "Exception in thread "main" java.lang.OutOfMemoryError: Java heap space ". How can I solve this problem? Can anyone explain me why this problem occurs? Thanks in advance.

5
Contributors
5
Replies
6
Views
12 Years
Discussion Span
Last Post by jwenting
0

I would guess you're using recursion...maybe?
Recursion can cause this, and so can many other things. Explain what your program is doing, please.

0

Recursion causes StackOverflow, not often OutOfMemory :)

You're probably trying to read in some very large file or otherwise reserving a lot of memory.
Figure out where you are doing that and try to find a way around it.

0

Just adding to what the two above stated...

Look to see if you're creating lots of new objects. Memory Exceptions ocure when your java application uses all of its allowed memory. I believe the default setting is 64megs. My guess is that inside a loop (if, while, or a recursive loop) there are new objects being created. While this isn't bad, it could be the source of the problem.

Regards,

Nate

0

Hi everyone,

I thnk you will have to use -Xms and -Xmx as such

java -Xms<initial heap size> -Xmx<maximum heap size>

You best bet is make your own mini application launcher to get around this problem.

Richard West

0

Unless there's a definite limit to the amount of memory the application will claim (so no errors or unforeseen conditions causing infinite loops for example) that will only delay the inevitable :)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.