Alessandro Lacava

on Designing and Developing Software. In love with Functional Programming.

OutOfMemoryError In Eclipse | Java Virtual Machine (JVM)

OutOfMemoryError in Eclipse | Java Virtual Machine (JVM)

It might happen that while running a Java application within the Eclipse environment you get an OutOfMemoryError due to the maximum amount of memory dedicated to the heap. You can fix it by increasing the minimum (-Xms parameter) and maximum (-Xmx parameter) heap size. You can do it in two different ways:

  1. By editing your eclipse.ini file you find under your Eclipse installation directory. Within that file you should find two lines similar to the following ones:

-Xms40m -Xmx512m

You might want to change them depending on your hardware. For example I changed them as follows:

-Xms256m -Xmx1024m

It means: “start with an initial heap size of 256 MB and grow to a maximum of 1024MB, that is 1GB.”

  1. By editing the Run Configurations in Eclipse. To do this, right-click on the class you want to run (the one with the main method) and then select:

Run As -> Run Configurations

Click on the Arguments tab. In the VM Arguments box type:

-Xms256m -Xmx1024m

or whatever you prefer, depending on the hardware you possess.

IMPORTANT NOTE: It is strongly recommended that you make a backup copy of your eclipse.ini file before editing it in any way.