Java 如何在 IntelliJ 中分析堆转储?(内存泄漏)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26460410/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 02:33:40  来源:igfitidea点击:

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

javaintellij-ideaheap-dumpjmapmemoryanalyzer

提问by vikingsteve

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

我已经从我的 Java 应用程序生成了一个堆转储,该应用程序已经使用该jmap工具运行了几天-> 这会产生一个大的二进制堆转储文件。

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

如何在 IntellIJ IDEA 中执行此堆转储的内存分析?

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

我知道有适用于 Eclipse 和 Netbeans 的工具,但如果可能的话,我宁愿使用 IDEA。

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.

分析的基本结果会告诉我每个类在内存中的每个对象的实例数,以便我能够开始调试内存泄漏。

采纳答案by Meo

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

最好的东西是Memory Analyzer (MAT),IntelliJ 没有任何捆绑的堆转储分析器。

回答by mcfinnigan

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

您可以从这里安装 JVisualVM 插件:https://plugins.jetbrains.com/plugin/3749?pr =

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

这将允许您分析插件中的转储。

回答by Katerina A.

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

您还可以使用 VisualVM Launcher 从 IDEA 中启动 VisualVM。 https://plugins.jetbrains.com/plugin/7115?pr=idea我个人觉得这更方便。

回答by Deniss M.

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

在插件存储库中还存在一个“JVM 调试器内存视图”,这可能很有用。

回答by jaken chen

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

您可以运行位于的“Java VisualVM” jdk/bin/jvisualvm.exe

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

这将打开一个 GUI,使用“文件”菜单 ->“加载...”然后选择您的 *.hprof 文件

That's it, you're done!

就是这样,你完成了!

回答by nbtk

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

我想将上面的答案更新到 2018 年,并说要同时使用 VisualVM 和 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.

VisualVM 用于实时监控和转储堆。您还可以在那里以强大的功能分析堆转储,但是 MAT 具有更多功能(例如自动分析以查找泄漏),因此,我将 VisualVM 转储输出(.hprof 文件)读入 MAT。





Get VisualVM:

获取 VisualVM:

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

在此处下载 VisualVM:https: //visualvm.github.io/

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

您还需要下载 Intellij 插件: enter image description here

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

然后你会在 intellij 中看到另外 2 个新的橙色图标: 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

使用橙色运行应用程序后,在 VisualVM 中,您将在左侧看到您的进程,在右侧看到数据。坐下来学习一下这个工具,它非常强大: enter image description here





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

独立获取 Eclipse 的内存分析工具 (MAT):

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

在这里下载:https: //www.eclipse.org/mat/downloads.php

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

这是它的外观: enter image description hereenter image description here

Hope it helps!

希望能帮助到你!

回答by Vicky

VisualVM plugin for Intellij Idea

Intellij Idea 的 VisualVM 插件

enter image description here

enter image description here