Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I analyze a heap dump in IntelliJ? (memory leak)

I have generated a heap dump from my java application which has been running for some days with the jmap tool -> this results in a large binary heap dump file.

How can I perform memory analysis of this heap dump within IntellIJ IDEA?

I know that there are tools for Eclipse and Netbeans but I would rather use IDEA if possible.

The basic results of the analysis would tell me the number of instances of each object in memory, per-class, to allow me to be able to start debugging memory leaks.

like image 737
vikingsteve Avatar asked Oct 20 '14 07:10

vikingsteve


People also ask

How do you Analyse a memory leak for heap dump?

A dump can be taken on demand (using the jmap JDK utility) or when an app fails with OutOfMemoryError (if the JVM was started with the -XX:+HeapDumpOnOutOfMemoryError command line option). A heap dump is a binary file of about the size of your JVM's heap, so it can only be read and analyzed with special tools.

How do I find memory leaks in IntelliJ?

From the main menu, select View | Tool Windows | Profiler. Right-click the necessary process in the Profiler tool window and select CPU and Memory Live Charts. A new tab opens in which you can see the amount of resources the selected process consumes.

How do you find a memory leak in a thread dump?

To track down a memory leak, you'll need a "heap dump" with a summary of the live objects in a leaky process. To record a dump, first run jps to find the process's PID, then run jmap -dump:live,format=b,file=(dumpfile) (pid) .


2 Answers

The best thing out there is Memory Analyzer (MAT), IntelliJ does not have any bundled heap dump analyzer.

like image 143
Meo Avatar answered Sep 16 '22 15:09

Meo


I would like to update the answers above to 2018 and say to use both VisualVM and Eclipse MAT.

How to use:

VisualVM is used for live monitoring and dump heap. You can also analyze the heap dumps there with great power, however MAT have more capabilities (such as automatic analysis to find leaks) and therefore, I read the VisualVM dump output (.hprof file) into MAT.



Get VisualVM:

Download VisualVM here: https://visualvm.github.io/

You also need to download the plugin for Intellij: enter image description here

Then you'll see in intellij another 2 new orange icons: enter image description here

Once you run your app with an orange one, in VisualVM you'll see your process on the left, and data on the right. Sit some time and learn this tool, it is very powerful: enter image description here



Get Eclipse's Memory Analysis Tool (MAT) as a standalone:

Download here: https://www.eclipse.org/mat/downloads.php

And this is how it looks: enter image description here enter image description here

Hope it helps!

like image 39
nbtk Avatar answered Sep 19 '22 15:09

nbtk