How to deal with “java.lang.OutOfMemoryError: Java heap space” error

When you encounter this type of error, it means that you have run out of memory in the heap while running your Java application.

There are many different reasons to why this could happen, and if you feel the default size of the heap should be enough then you’d probably should take a good look at the code and see if things can be done differently. Otherwise you could set the max heap size through a parameter to the JVM.

In your IDE, locate the place where VM arguments is set and add:


to set the max heap size. The example above sets it to about 2Gb.

Search for more Java info on this site here:
Custom Search

Please type any questions here.