Thursday, April 12, 2007

What will you do if VM exits while printing "OutOfMemoryError" and increasing max heap size doesn't help?

The Java HotSpot VM cannot expand its heap size if memory is completely allocated and no swap space is available. This can occur, for example, when several applications are running simultaneously. When this happens, the VM will exit after printing a message similar to the following.

Exception java.lang.OutOfMemoryError: requested bytes

If you see this symptom, consider increasing the available swap space by allocating more of your disk for virtual memory and/or by limiting the number of applications you run simultaneously. You may also be able to avoid this problem by setting the command-line flags -Xmx and -Xms to the same value to prevent the VM from trying to expand the heap. Note that simply increasing the value of -Xmx will not help when no swap space is available.

3 comments :

Anonymous said...

I think you can get OutOfMemoryError when you run out of Perm Generation space too...

Anonymous said...

Also a recursive call can exhaust stack frames for a particular thread that will cause OutOfMemoryError.

RichardVerSteeg on December 15, 2011 at 8:31 AM said...

Your default response to an OutOfMemoryException should be to review your logs, use a memory profiler, etc. You should verify that you don't have a resource leak and/or that you aren't inadvertantly consuming more memory then neccessary. Allocating more resources to the JVM may mask a serious problem in your code.

 

Disclaimer
Interview Questions On Java,Java EE Copyright © 2017. Reads: best tracker