Java applications are allocated memory, called "heap" memory, to store data dynamically created during the execution of a program. Java applications launch with a starting amount of heap memory, and may be allocated a maximum amount of heap memory, which is used as the application's needs increase. Typically, the minimum and maximum amounts of allocated heap memory, or "heap size," are determined by the default values for your operating system and version of Java. However, if an application requires more than the maximum allocated amount of memory, an "out-of-memory" error occurs. The starting and maximum heap sizes for a Java application can be set in Microsoft Windows XP by adding or modifying the heap size flags on the Java application shortcut. The maximum amount of heap memory that can be allocated is approximately 1.6 gigabytes.
- Skill level:
Other People Are Reading
Right-click on your Java application shortcut and select "Properties."
In the "Target" line under the "Shortcut" tab, add the initial heap size flag " -Xms32M " after the word "java" (with a space before and after the flag). This sets the initial heap size for the application to 32 megabytes. If you want the application to start with more or less allocated heap memory, change "32" to the number of megabytes, for example "-Xms128M" for 128 MB.
Add the maximum heap size flag "-Xmx128M" (with a space before and after the flag). This sets the maximum heap size for the application to 128 MB. If you want the application to have a higher maximum heap size available, change "128" to the number of megabytes your application requires. For example, write "-Xms512M" for 512 MB. The maximum heap size should be larger than the initial heap size.
Click or double-click the shortcut to launch the Java application. If you continue to receive out-of-memory errors, repeat these steps, increasing the value for the maximum heap size flag.
Tips and warnings
- If you are running a Java application from the command line, simply add the -Xms and -Xmx flags with appropriate values to the command line. For example, to start "myapp" with an initial heap size of 64 MB and maximum heap size of 512 MB, use the command:
- Java -Xms64m -Xmx512m myapp
- 20 of the funniest online reviews ever
- 14 Biggest lies people tell in online dating sites
- Hilarious things Google thinks you're trying to search for