Allows an Object to attempt to free resources and perform other cleanup operations before the Object is reclaimed by the Garbage Collector (GC). This method may be ignored by the runtime; therefore, necessary cleanup operations should be done elsewhere.
[Visual Basic] Overridable Protected Sub Finalize() [C#] protected virtual void Finalize(); [C++] protected: virtual void Finalize(); [JScript] protected function Finalize();
None.
This method is invoked some time after the GC determines that the current Object is no longer being referenced by any other Object.
Notes to Implementers:
Finalize does nothing by default. It must be overridden by a derived class, because reclamation by the GC tends to take much longer if a Finalize operation must be run.
If an Object holds references to any resources, Finalize must be overridden by a derived class in order to free these resources before the Object is discarded by the GC.
Finalize may take any action, including resurrecting an object (that is, making the object accessible again) after it has been cleaned up by the GC. However, the object can only be resurrected once; the GC will not call Finalize on resurrected objects.
Finalize operations have the following limitations:
Object Class | Object Members | System Namespace | GC | WeakReference