Finalizers in C#

Finalizers are class methods that are executed before the garbage collector frees the memory of a referenced object no longer in use. The syntax for a finalizer is the name of the class to which the tilde sign ~ preceeds:

class TestClass1
{
  ~ TestClass1 () {... }
}

The above code is converted by the compiler to the following method declaration:

protected override void Finalize ()
{
  ...
  base.Finalize ();
}

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.