Home  >  Article  >  Java  >  How to Fix \'java.lang.OutOfMemoryError: Java heap space\' by Increasing JVM Heap Size?

How to Fix \'java.lang.OutOfMemoryError: Java heap space\' by Increasing JVM Heap Size?

Susan Sarandon
Susan SarandonOriginal
2024-11-01 14:36:02267browse

How to Fix

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:

  • -Xms: Initial heap size
  • -Xmx: Maximum heap size
  • -Xss: Thread stack size

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn