Garbage Collection(GC)
1.In C#, the deallocation or freeing of resources consumed by created instances occurs automatically on a system-determined schedule by an intelligent mechanism known as garbage collection.
For Eg:
The Garbage Collector (GC) is like a sweeper fish in an aquarium. If you drop more food than the other fish can eat, the sweeper fish consumes the remaining food without leaving any behind.
The GC in C# improves on the concept because it does not reduce the system's performance until really needed.
You can overcome the disadvantages of GC's nondeterministic behavior by using destructors (dtors) and finalizers.
You can allocate member instances with constructors (ctors).
class X
{
// implicit dtor ~X()
// created for you automatically by C#
}
class Y
{
~Y() // explicit dtor, same as Finalize
{
// some code
}
}
//verbose syntax:
class Z
{
protected override void Finalize() //verbose explicit dtor, same as ~
{
// Some code
// implicit call to base.Finalize();
}
}
Kalithmk, if this helps please login to Mark As Answer. | Alert Moderator