How to Change Java Memory Heap Size
Java applications execute on a Java Virtual Machine (JVM). The JVM has been ported to all current operating systems; it accepts multiple command-line parameters, most of which are optional. Two of those parameters determine the amount of memory the JVM will allocate for the heap needs of the Java application. You can change those parameters by invoking the JVM with appropriate parameter values.
Instructions
-
-
1
Click "Start" and type "run" into the search box. Click "Run," then type "cmd" and press "Enter." Windows will open a new command prompt window.
-
2
Change the current command folder to the location where your compiled Java application is stored, as in the following example:
C:
cd "C:\Documents and Settings\manola\javaDev"
Replace "C:\Documents and Settings\manola\javaDev" with the path to the application folder, and "C:" by the corresponding drive. Press "Enter" after each line.
-
-
3
Start the JVM on your application while using non-default parameters for the size of the heap, as in the following command:
java -Xms6MB -Xmx256MB myRootClass.class myArgs
Replace "6" by the initial heap size you want -- in megabytes; default is 2 -- and "256" by the maximum size for the memory allocation pool -- in megabytes; default is 64. Replace "myRoot.class" with the name of the class that contains the main method and "myArgs" with any arguments your application needs. Press "Enter."
-
1