Pages Navigation Menu

Coding is much easier than you think

How to increase JVM heap size in Eclipse

How to increase JVM heap size in Eclipse

 
To avoid getting java.lang.OutOfMemoryErrors, while running web application, we should increase heap size allocated by the JVM by using command line options.
 

-Xms        set initial Java heap size
-Xmx        set maximum Java heap size
-Xss        set java thread stack size

 

To do this, follow these steps:

1. Open the Server Configuration in Eclipse by double-clicking on the Server instance.
 
Server
 

2. Click on “Open launch configuration” link
 
Increase JVM max heap size eclipse
 
3. Click on the Arguments tab and add the following command at the end of VM arguments: -Xms128m –Xmx1024m.
 
Increase JVM max heap size eclipse
 

These values may vary, depending on requirement/available memory

 
If you are not using any server, you can type the following on the command line before you run your program:

java -Xms64m -Xmx1024m MyProgram

 

Note:

  • Do not set -Xmx to too small value
  • Set -Xms to a small value

Setting -Xmx to small value mostly leads to OutOfMemoryErrors, because this is the maximum amount of memory you are allocating for Java and it cannot utilize memory beyond the set value.

Also If you set -Xms to higher value you might run out of memory. So try to keep it to a small value like -Xms16m.
 

One Comment

  1. Thanks a lot :)