Example usage for java.lang.management MemoryMXBean gc

List of usage examples for java.lang.management MemoryMXBean gc

Introduction

In this page you can find the example usage for java.lang.management MemoryMXBean gc.

Prototype

public void gc();

Source Link

Document

Runs the garbage collector.

Usage

From source file:org.rhq.enterprise.agent.promptcmd.GCPromptCommand.java

private void freeMemory(PrintWriter out) {
    final MemoryMXBean memoryMxBean = ManagementFactory.getMemoryMXBean();

    printGlobalMemoryUsage(out, memoryMxBean);

    // free up some global static caches
    Introspector.flushCaches();// ww w . jav a  2 s .  co m
    LogFactory.releaseAll();

    // invoke the garbage collector
    out.println(MSG.getMsg(AgentI18NResourceKeys.GC_INVOKE));
    memoryMxBean.gc();

    printGlobalMemoryUsage(out, memoryMxBean);
    return;
}