- A finalize () method is defined in the object class. A finalize () executes when the object is destroyed.
- Each class in C# is automatically (implicitly) inherited from the Object class which contains a method finalize (). This method is guaranteed to be called when your object is garbage collected (removed from memory). You can override this method and put here code for freeing resources that you reserved when using the object.
E.g.: protected override void finalize ()
{
try
{
Console.WriteLine("Destructing Object….");
//put some code here
}
finally
{
base.Finalize();
}
}
finalize()
Subscribe to:
Post Comments
(
Atom
)
0 comments :
Post a Comment