Increase heap size

Increase heap size in java

Set or Increase the maximum heap size:

java -Xmx256m TestData.java

Where:
TestData.java: represents java application file.

Java command memory options

$ java -X

-Xmixed                  mixed mode execution (default)
-Xint                    interpreted mode execution only
-Xbootclasspath:         set search path for bootstrap classes and resources 
-Xbootclasspath/a:       append to end of bootstrap class path 
-Xbootclasspath/p:       prepend in front of bootstrap class path 
-Xnoclassgc              disable class garbage collection 
-Xloggc:                 log GC status to a file with time stamps
-Xbatch                  disable background compilation
-Xms                     set initial Java heap size
-Xmx                     set maximum Java heap size
-Xss                     set java thread stack size
-Xprof                   output cpu profiling data
-Xfuture                 enable strictest checks, anticipating future default
-Xrs                     reduce use of OS signals by Java/VM (see documentation)
-Xdock:name=             override default application name displayed in dock 
-Xdock:icon=             override default icon displayed in dock 
-Xcheck:jni              perform additional checks for JNI functions 
-Xshare:off	         do not attempt to use shared class data 
-Xshare:auto             use shared class data if possible (default) 
-Xshare:on	         require using shared class data, otherwise fail.

Options to change Heap Size

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

Note: By-default size will be in bytes but we can use following options also:

  1. “m” or “M” for MB
  2. “g” or “G” for GB

Increase heap size in Eclipse

Right click on Run As –> Run Configuration –> Arguments –> Vm Arguments and then add

-Xms2048m -Xmx2048m

Increase heap size in NetBeans

Go to Run –> Set Project Configuration –> Customise –> run of its popped up window –> VM Option and then add

-Xms2048m -Xmx2048m

Increase heap size in tomcat

  • Go at server directory: tomcat/bin
  • Open catalina.sh file.
  • Change JAVA_OPTS to below :
    JAVA_OPTS="-Djava.awt.headless=true -Dfile.encoding=UTF-8 -server -Xms1536m 
    -Xmx1536m -XX:NewSize=256m -XX:MaxNewSize=256m -XX:PermSize=256m 
    -XX:MaxPermSize=256m -XX:+DisableExplicitGC"
    
  • Restart tomcat

Increase heap size for Maven

  • Go to maven directory C:\apache-maven-2.2.1\bin
  • Open mvn.bat file
  • Add the below (Unix/Linux):
    export MAVEN_OPTS=-Xmx512m
    
  • Add the below (windows):
    set MAVEN_OPTS=-Xmx512m
    

Increase heap size for Ant

  • Go to ant home directory (ANT_HOME)
  • Open ant.bat file
  • Add the below (Unix/Linux):
    export ANT_OPTS=-Xmx512m
    
  • Add the below (windows):
    set ANT_OPTS=-Xmx512m
    
Please Share