What does "Perform GC" button do in jconsole?

garbage-collection, java, jmx

Solution

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.

Problem

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

Original source