Hi Niu,
From my understanding of this here's how this works.
System.gc() is an explicit call to the garbage collector. However, this is only a suggestion to run, as when it runs and when unreferenced objects are run is up to the VM.
System.runFinalization() - A method may implement the finalize() method inherited from the Object class to cleanup after itself (memory, other resources etc.). The finalize() method is called by the garbage collector before it
disposes of the object. The System.runFinalization() method is an explicit call that executes the finalize() methods of any objects
awaiting garbage collection. There is no guarantee which order finalize() methods are called on objects awaiting gc.
System.runFinalizersOnExit( true )-
(from 1.4.1 spec)Deprecated. This method is inherently unsafe. It may result in finalizers being called on live objects while other threads are concurrently manipulating those objects, resulting in erratic behavior or deadlock.
essentially what this does is run the finalize() method of objects which have not been garbage collected when the rruntime exits.
Hope this helps,
Kem
Originally posted by Niu Xiuyuan:
System.runFinalization();
System.runFinalizersOnExit( true );
System.gc()
who can explain those functions in detail, and where and how to use them in practice.