If a program throws the error java.lang.OutOfMemoryError: Java heap space
, it simply means that the program while running has exhausted all the heap space and even the garbage collector has not been able to reclaim the heap space from unused objects. Read my blog on How to simulate java.lang.OutOfMemoryError: Java heap space.
There are following two options to solve java.lang.outofmemoryerror java heap space:
- Provide more memory to the JVM through the -Xmx VM argument. To know how to do this, read my blog on How To Increase JVM Heap Size In Eclipse.
- Fix your program itself so that it uses memory efficiently and also releases the heap space at the right point when it is no longer using it. Very often this is the best way to solve java.lang.OutOfMemoryError problems.
How to solve java.lang.OutOfMemoryError: Java Heap Space