How to take Heap dumps

Heap dumps provide information about the contents of JVM Heap. They are very helpful to know which object are occupying memory and the their links to the root objects. Let’s see different options to take Heap dumps

Using command line option on OOME

This has been discussed in detail here

Using jmap

jmap is a tool that ships with JDK. We can use jmap to generate heap dumps. Following is a sample of how to do it

jmap -heap 5674

Where 5674 is the Java process id.

jmap supports different options, which can be found here

Using VisualVM

VisualVM is a wonderful tool that comes in handy for a lot of tasks. We have already seen how to use it to take Thread dumps. We can use it to generate and analyse heap dumps as well. Launch VisualVM and connect to the Java application whose Heap dump is needed.


Right click on the process whose Heap dump is needed and click Heap dump. Here we are taking the Heap dump of VisualVM process itself. VisualVM shall take the Heap dump and open another tab with details of Heap. The image below shows the classes. VisualVM can also be used to analyse memory leaks.


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.