JDownloader
There was a problem loading the comments.

Reducing Unused JVM Heap Memory Usage

Support Portal  »  Knowledgebase  »  Viewing Article


Reducing Unused JVM Heap Memory Usage (Java 11+)

By default, the Java Virtual Machine (JVM) often holds onto allocated RAM even when the application is idle and large portions of the heap are free. This improves performance during sudden load spikes, but can cause unnecessarily high memory consumption on systems with limited RAM.

If you are running Java 11 or newer (using the default G1 Garbage Collector), you can instruct the JVM to release unused heap memory back to the operating system more aggressively.

Recommended VM Parameters

Add the following parameters to your startup configuration / .vmoptions file:

-XX:MinHeapFreeRatio=10 -XX:MaxHeapFreeRatio=20

 

Optional (Java 12+ only):

If the application stays idle for long periods and does not trigger regular garbage collection cycles, you can also add:

-XX:G1PeriodicGCInterval=60000

 

Parameter Breakdown

  • -XX:MaxHeapFreeRatio=20 (Default: 70) Defines the maximum percentage of free heap space allowed after a garbage collection cycle before the JVM shrinks the heap. Lowering this from 70% to 20% forces the JVM to return unused memory to the OS much sooner.

  • -XX:MinHeapFreeRatio=10 (Default: 40) Defines the minimum percentage of free heap space maintained after shrinking. Keeping this below MaxHeapFreeRatio prevents the heap from constantly expanding and shrinking again.

  • -XX:G1PeriodicGCInterval=60000 (Optional, Java 12+ only) Triggers a periodic garbage collection check every 60,000 ms (60 seconds) if no regular GC has occurred. This ensures unused memory is released even when the application is completely idle.

Version Compatibility & Notes

  • Java 11+ Required: While MinHeapFreeRatio and MaxHeapFreeRatio exist in older Java versions, they only work reliably with the default G1 Garbage Collector starting in Java 9 / Java 11. Do not use these flags on Java 8 if you rely on G1GC.

  • Java 12+ for Periodic GC: The -XX:G1PeriodicGCInterval flag was introduced in Java 12. Adding it to a Java 11 runtime will prevent the JVM from starting (Unrecognized VM option).

  • Performance Trade-off: Releasing memory aggressively means the OS may need to re-allocate RAM when heavy tasks start. If you experience minor CPU spikes or brief pauses during load bursts, slightly increase the values (e.g., MinHeapFreeRatio=15 and MaxHeapFreeRatio=30).


Related Articles


On-Premise Help Desk Software by SupportPal