What is the use of garbage control

Posted by Kalithmk under C# on 11/13/2014 | Points: 10 | Views : 265 | Status : [Member] | Replies : 1
Hi All
What is the use of garbage control?, when we go for this? i need answer with small example, thanks in advance


Posted by: Punitha on: 12/4/2014 [Member] Starter | Points: 25

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

Login to post response