It so happen that im reading Effective Java
ITEM 7: AVOID FINALIZERS
Finalizers are unpredictable, often dangerous, and generally
unnecessary. -Effective Java (page 50)
another one from pdf.
Don’t be seduced by the methods System.gc and System.runFinalization .
They may increase the odds of finalizers ge tting executed, but they
don’t guaran- tee it. The only methods that claim to guarantee
finalization are System.runFi- nalizersOnExit and its evil twin,
Runtime.runFinalizersOnExit . These methods are fatally flawed and
have been deprecated [ThreadStop].
based on this using System.gc will only increase the odds of finalizers getting executed and importantly using it will not guarantee that it will run the Garbage Collection, it is only suggesting to the jvm.
another one.
Not only does the language specification provide no guarantee that
finalizers will get executed promptly; it provides no guarantee that
they’ll get executed at CHAPTER 2 CREATING AND DESTROYING OBJECTS 28
all. It is entirely possible, even likely, that a program terminates
without executing finalizers on some objects that are no longer
reachable