How to Generate and Analyse Java Heap Dump

How to Generate and Analyse Java Heap Dump



1 min read

Play this article


Install and Setup Java - How do I install Java?


  1. Write and execute a simple Java program.

      public class SimpleJavaProgram {
         public static void main(String[] args) {
                List<String> list = null;
                while(true) {
                       list = new ArrayList(); //Memory leak
  2. Go to cmd and execute "jps" to find the JVM ID(vmid) of the running application. JPS stands for Java Virtual Machine Process Status Tool and this tool is used to list the JVMs runningn on the system.

  3. Now run the "jmap" command to generate the heap dump using the above vmid.JMap stands for Java Memory Map and returns the heap memory details.

     jmap -dump:file=heapDump.jmap <vmid>
  4. Run "jhat" on the heap dump generated to analyze the heap dump. Jhat stands for Java Heap Analysis Tool. It is used to analyze and monitor the heap dump.

     jhat heapDump.jmap
  5. Analyze the heap dump from the below links:


    You can also view the objects and instance counts in the histogram.