How to take a heap dump before OutOfMemory crash

Shani Attias
2021-05-20 12:09

A heap dump is a snapshot of all the objects that are in memory in the JVM at a certain moment. They are very useful to troubleshoot memory-leak problems and optimize memory usage in Java applications.

In order to capture a heap dump automatically, we need to add the HeapDumpOnOutOfMemoryError command-line option that generates a heap dump when a java.lang.OutOfMemoryError is thrown.

 

Artifactory version 6.x:

Add the below JVM flag to the Artifactory default file, the file name and location are different for each installation type, please refer to our wiki page, “Setting Java Memory Parameters” for the correct name and location to your installation.
For the change to take effect, you will need to restart Artifactory.

 

-XX:+HeapDumpOnOutOfMemoryError
-XX:HeapDumpPath=/path/to/artifactoryheapdump.bin

 

* Keep in mind the location – the memory dump can be large in size.

 

Artifactory version 7.x:

Add the below snippet to the system.yaml file. For the change to take effect, you will need to restart Artifactory.

shared:
  extraJavaOpts: "-XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/path/to/artifactoryheapdump.bin”

 

* Keep in mind the location – the memory dump can be large in size.