Increasing Heap Size of JVM: Resolving OutOfMemoryError
When encountering the "java.lang.OutOfMemoryError: Java heap space" error, it is likely that the Java Virtual Machine (JVM) has run out of memory. To prevent this issue, you can increase the heap size of the JVM.
Heap Size Parameters
The heap size of the JVM can be adjusted using the following parameters:
Increasing the Heap Size
To increase the heap size, specify the -Xmx parameter with the desired size. For instance, to set the maximum heap size to 256 megabytes (MB), use the following command:
java -Xmx256m <program_name>
Example
In your case, the OutOfMemoryError is reported in the TestData.java program. To resolve this issue, you can increase the heap size as follows:
java -Xmx256m TestData.java
The above is the detailed content of How to Fix \'java.lang.OutOfMemoryError: Java heap space\' by Increasing JVM Heap Size?. For more information, please follow other related articles on the PHP Chinese website!