How to generate a heap dump?


  • How do I generate a heap dump.
  • Diagnosing memory issues: OutOfMemoryError (OOM). Analyzing possible Memory Leaks.


A heap dump is a snapshot of the memory of a Java process at a certain point of time. There are different formats for persisting this data, and depending on the format it may contain different pieces of information, but in general the snapshot contains information about the java objects and classes in the heap at the moment the snapshot was triggered. Usually a full GC is triggered before the heap dump is written so it contains information about the remaining objects.

1. Get the PID of the Java process where Jenkins is running

To generate a head dump the first part is to obtain the process id (or PID). There are multiple methods to obtain the PID:

  • jps - From Unix Terminal or Windows Cmd with the JDK installed into the OS. Lists the instrumented Java Virtual Machines (JVMs) on the target system.
  • ps -ef | grep java - From Unix Terminal only. It is used to obtain the process id of all java processes.
  • Process explorer - There are task manager UI applications (System Tools) which can be used to obtain the process id. Find the process and view its PID in the corresponding column.
    • On Windows and Linux (Ubuntu) is named as Task manager
      • On Mac OS is named as Activity Monitor

2. Get the head dump

After obtaining the process id ($PID), the next step is to generate the heap dump:

  • jmap -dump:format=b,file=$FILENAME.bin $PID - From Unix Terminal or Windows Cmd with the JDK installed into the OS. It prints shared object memory maps or heap memory details for a process, core file, or remote debug server. Please, change the $FILENAME for any of the heap dumps you would like to send to us.
  • At CloudBees, we have our own scripts that we would attach to the ticket in case we consider is relevant for diagnosing your issue.

Generating a few of these heap dumps during the OOM issue would be required. Attach the output generated from these commands to a cloudbees support ticket, so we can help diagnose further.


  1. Some of these commands might require admin permissions.
  2. When JDK is required (it does not mean JRE). To run the proposed commands you need to run them from $JDK_PATH/bin or from anywhere by including $JDK_PATH/bin into your System $PATH. On the other hand, since JDK7 Update 21, the server JRE includes these tools IIRC as well.
  3. For Windows > Task Manager if PID is not displayed > click View - Select Columns > Select the PID (Process Identifier).
  4. Unix Terminal includes Linux and MacOS OS.
  5. As an option, for running Unix commands into Windows Cygwin can be installed.
  6. Please check the KB CloudBees Jenkins Platform supported Java versions.




Have more questions? Submit a request


Please sign in to leave a comment.