As discussed in my blog How to solve java.lang.OutOfMemoryError: Java Heap Space, if a Java program running in Eclipse throws java.lang.OutOfMemoryError: Java heap space, one of the solutions to solve this error is to assign more memory for JVM.

Following are the steps to increase JVM heap size in Eclipse:

Step 1

Open Eclipse and in the toolbar menu, go to Run -> Run Configurations…

Go to Run Configuration

Step 2

In the left pane of Run Configurations window, navigate to the Java Application node and select the Java application for which you need to increase the heap size. Then in the right pane, click on the Arguments tab.

Select Java application for changing heap size

In the VM Arguments section, type the following arguments:
-Xms[CUSTOM_SIZE] – This means that your JVM will be started with Xms amount of memory
-Xmx[CUSTOM_SIZE] – This means that your JVM will be able to use a maximum of Xmx amount of memory.

For example,
-Xms512M – JVM will start with an initial memory size of 512 MB
-Xmx1024M – and can use up to a maximum of 1024 MB (or 1 GB).

Click on Apply button to save the changes.

Provide VM params for memory
Note
The memory settings for Java programs running in Eclipse are different from the memory settings for eclipse itself. For increasing or decreasing the amount of memory used by Eclipse, changes should be made in the eclipse.ini file and NOT in the Run Configuration.
How to increase JVM heap size in Eclipse
        

Comments, Questions or Suggestions: