Home > Java > javaTutorial > body text

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

Susan Sarandon
Release: 2024-11-01 14:36:02
Original
272 people have browsed it

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>
Copy after login

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
Copy after login

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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template