Calling System.gc()
or 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:
An application relying on those unpredictable methods is also unpredictable and therefore broken.
The task of running the garbage collector should be left exclusively to the JVM.