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.

Recommended Answers

All 5 Replies

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.

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.

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

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.