< Prev
Next >

C# Destructor

In C#, a constructor is class member, which is used to create and initialize the objects of a class. Contrary to the working of a constructor, a destructor is a special method and also a class member, which is executed right before an object is de-allocated from the memory by the garbage collector.

A destructor is required in a situation when we want to ensure that the object terminates cleanly by releasing some resources which could be used by the object in question.

A general form of a destructor

Let us show you a general form of a destructor.
	//statements in destructor

Some important features of a destructor are -

When a destructor is called?

When the garbage collector runs, it frees up the space in memory by finding and deleting those objects on it that are not referenced by any live program i.e. the unreferenced objects, which are no longer in use. At that time, it automatically calls the destructor associated with an object in question, right before the object is taken off the memory.

Please Subscribe

Please subscribe to our social media channels for daily updates.

Decodejava Facebook Page  DecodeJava Twitter Page Decodejava Google+ Page



Please check our latest addition