What does “Perform GC” button do in jconsole?

↘锁芯ラ 提交于 2019-12-23 12:42:22

问题


There is a button "Perform GC" in jconsole, anyone knows what exactly happens if I click that button, it's invoking System.gc()?


回答1:


You can find out by yourself. The code of JConsole is part of OpenJDK. You can also check it out on grepcode.com.

The button calls a gc() method of an object implementing MemoryMXBean which is most probably implemented by com.sun.management.MemoryImpl class. This class contains an implementation of gc() method which looks like this:

public void gc() {
    Runtime.getRuntime().gc();
}

Now, if you consider the implementation of gc() method in java.lang.System which looks like this:

public void gc() {
    Runtime.getRuntime().gc();
}

the answer to your question is: Technically no, but it does the same thing.




回答2:


According to this link, yes, it does perform System.gc().




回答3:


Pretty much. The GC Button in the MemoryTab in JConsole calls MemoryTab.gc() which in turn calls the target JVM's MemoryMXBean.gc(). The javadoc says this call is equivalent to java.lang.System.gc().




回答4:


I fear they do pretty much the same under the hood, but I'm not sure I agree with the description that says:

The Memory tab features a “Perform GC” button that you can click to perform garbage collection whenever you want.

When actually System.gc() is just a suggestion for the VM:

Calling the gc method suggests that the Java Virtual Machine expend effort toward recycling unused objects in order to make the memory they currently occupy available for quick reuse. When control returns from the method call, the Java Virtual Machine has made a best effort to reclaim space from all discarded objects.

Should they do the same, I would not dare to say you can do it whenever you want.



来源:https://stackoverflow.com/questions/14902496/what-does-perform-gc-button-do-in-jconsole

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!