简体   繁体   English

JConsole 中的内存泄漏是什么样的?

[英]What does a memory leak look like in JConsole?

I am trying to use JConsole to see if I have a memory leak but do not know what to look for.我正在尝试使用 JConsole 来查看是否存在内存泄漏但不知道要查找什么。 If I had to guess, the memory usage should always go up, despite garbage collection, like this:如果我不得不猜测,尽管垃圾收集,内存使用量应该总是上升,如下所示:

在此处输入图片说明

As you can see in my other SO question, I'm seeing a jagged edge, where the memory usage goes up—even if the browser is closed and no requests are hitting my local Tomcat server—and then go down.正如您在我的另一个 SO 问题中看到的那样,我看到了一个锯齿状边缘,内存使用量上升 - 即使浏览器关闭并且没有请求访问我的本地 Tomcat 服务器 - 然后下降。

在此处输入图片说明

What does a memory leak in Java "look like" in JConsole? Java 中的内存泄漏在 JConsole 中“看起来像”什么?

I think the best way to learn what a memory leak looks like is to do an experiment.我认为了解内存泄漏的最好方法是做一个实验。 Try something like this to create a memory leak:尝试这样的事情来创建内存泄漏:

    Collection<Object> data = new LinkedList<>();
    while(true) {
        long[] canBeGarbageCollected = new long[10000];
        long[] canNotBeGarbageCollected = new long[100];
        data.add(Arrays.asList(canNotBeGarbageCollected));
    }

Besides JConsole you also have VisualVM that has a nice plugin called "Visual GC".除了 JConsole,你还有 VisualVM,它有一个很好的插件叫做“Visual GC”。 Java Mission Control with Flight Recording can give you a lot of details. Java Mission Control with Flight Recording 可以为您提供很多细节。 A very powerful tool exists on the command line as well:命令行上也存在一个非常强大的工具:

jstat -gcutil -h20 $PID 1000

This will show that a memory leak will eventually lead to 100% Old space utilization (O) and the CPU will spend more and more time doing full garbage collections (FGCT)这将表明内存泄漏最终会导致 100% 旧空间利用率 (O),并且 CPU 将花费越来越多的时间进行完整垃圾收集 (FGCT)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM