Question: Is it possible to force garbage collection in Java, even if it is tricky to do? I know about `System.gc();` and `Runtime.gc();` but they only suggest to do GC. How can I force GC?

Answer: 
To manually Request GC (not from System.gc()) : 

1. Go To : bin folder in JDK eg.-C:\Program Files\Java\jdk1.6.0\_31\bin
2. Open jconsole.exe
3. Connect to the desired local Process.
4. Go To memory tab and click perform GC.
We can trigger `jmap -histo:live <pid>` using the java runtime. This will force a full GC on heap to mark all the live objects.

```
public static void triggerFullGC() throws IOException, InterruptedException {
    String pid = ManagementFactory.getRuntimeMXBean().getName().split("@")[0];
    Process process = Runtime.getRuntime().exec(
            String.format("jmap -histo:live %s", pid)
    );
    System.out.println("Process completed with exit code :" + process.waitFor());
}

```