Why is this an issue?
Runtime.getRuntime().gc() is a bad idea for a simple reason: there is no way to know exactly what
will be done under the hood by the JVM because the behavior will depend on its vendor, version and options:
- Will the whole application be frozen during the call?
- Is the
-XX:DisableExplicitGC option activated?
- Will the JVM simply ignore the call?
System.gc(), there is no reason to manually call
runFinalization() to force the call of finalization methods of
any objects pending finalization.
An application relying on these unpredictable methods is also unpredictable and therefore broken. The task of running the garbage collector and
finalize() methods should be left exclusively to the JVM.