C#

C#

Made by DeepSource

Rewrite virtual void Finalize() as ~Destructor() CS-P1010

Performance
Major

Destructors, 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 Finalizers are invoked by the runtime when deemed appropriate.

Bad Practice

virtual void Finalize()
{
    // ...
}

Recommended

~Foo()
{
    // ...
}

Reference