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

JavaIntellij IdeaHeap DumpJmapMemoryanalyzer

Java Problem Overview


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.

Java Solutions


Solution 1 - Java

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

Solution 2 - Java

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!

Solution 3 - Java

You can also use VisualVM Launcher to launch VisualVM from within IDEA. https://plugins.jetbrains.com/plugin/7115?pr=idea I personally find this more convenient.

Solution 4 - Java

There also exists a 'JVM Debugger Memory View' found in the plugin repository, which could be useful.

Solution 5 - Java

You can just run "Java VisualVM" which is located at jdk/bin/jvisualvm.exe

This will open a GUI, use the "File" menu -> "Load..." then choose your *.hprof file

That's it, you're done!

Solution 6 - Java

VisualVM plugin for Intellij Idea

enter image description here

Solution 7 - Java

Start from IntelliJ IDEA 2021.2, there is a feature called Open an external profiling report. The UI for the viewer like below: enter image description here

You can view the heap dump by either:

  1. View > Tool Windows > Profiler from main menu and click Open Snapshot
  2. Run > Open Profiler Snapshot > Open from main menu
  3. Drag the heap dump file into IntelliJ window

Solution 8 - Java

You can install the JVisualVM plugin from here: https://plugins.jetbrains.com/plugin/3749?pr=

This will allow you to analyse the dump within the plugin.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionvikingsteveView Question on Stackoverflow
Solution 1 - JavaMeoView Answer on Stackoverflow
Solution 2 - JavanbtkView Answer on Stackoverflow
Solution 3 - JavaKaterina A.View Answer on Stackoverflow
Solution 4 - JavaDeniss M.View Answer on Stackoverflow
Solution 5 - Javajaken chenView Answer on Stackoverflow
Solution 6 - JavaVikkiView Answer on Stackoverflow
Solution 7 - JavadaleqqView Answer on Stackoverflow
Solution 8 - JavamcfinniganView Answer on Stackoverflow