What is Garbage Collector?

 

  • In C#, every created object allocates memory. And we can need some memory space for any other objects. So these memory addresses need to be deallocate.  This could be possible by managing memory manually(mostly in old languages). But C# has an automatic memory manager and it is called Garbage Collector (GC). Garbage Collector releases the dead objects and the objects which are no longer needed, to free some memory space for live objects. This is what Garbage Collector is, with simple terms.

 

  • Garbage Collector collects objects when the following cases occur,

1)  When system has low physical memory.

2) When allocated memory exceeds pre-set threshold.

3) When GC.Collect method is called. (GC.Collect is called for unusual cases. Because Garbage Collector runs automatically for normal cases)

 

 

 

0 0 vote
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x