virtual void Finalize()
as ~Destructor()
CS-P1010Destructors, often represented as ~Foo()
(where Foo = class name) are used to perform clean-up operations when being garbage collected. Such calls are translated to override void Finalize()
automatically and contain further instructions to invoke the Finalize
method recursively for all the instances in the inheritance chain to perform a full clean-up. It is therefore recommended that you let the compiler and runtime do the translation and that you not explicitly define virtual void Finalize()
. Additionally, if you wish to perform clean-up operations such as closing file handles and database connections, it is recommended that you take a look at the IDisposable
interface as Finalize
rs are invoked by the runtime when deemed appropriate.
virtual void Finalize()
{
// ...
}
~Foo()
{
// ...
}