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: 
Under the documentation for [OutOfMemoryError](http://java.sun.com/javase/6/docs/api/java/lang/OutOfMemoryError.html) it declares that it will not be thrown unless the VM has failed to reclaim memory following a full garbage collection. So if you keep allocating memory until you get the error, you will have already forced a full garbage collection. 

Presumably the question you really wanted to ask was "how can I reclaim the memory I think I should be reclaiming by garbage collection?"
You can trigger a GC from the command line. This is useful for batch/crontab:

```
jdk1.7.0/bin/jcmd <pid> GC.run

```

See :

* <https://docs.oracle.com/javase/8/docs/technotes/guides/troubleshoot/tooldescr006.html>