Explain Garbage Collection in .Net

Question: Explain Garbage Collection in .Net


What is .NET garbage collection?
   The garbage collection (GC) is new feature in Microsoft . net framework. When we have a class that represents an object in the runtime that allocates a memory space in the heap memory. All the behavior of that objects can be done in the allotted memory in the heap.
  1. The .Net framework provides a new mechanism for releasing unreferenced objects from the memory this process is called garbage collection(GC).
  2. When program creates an object the object takes up the memory.
  3. Later  when the program has no more references to that  object the objects memory becomes unreachable but it is not immediately freed.
  4. The garbage collection checks to see if there are any objects in the heap that are no longer being used by the application.
  5. If such objects exist then the memory used by these objects can be reclaimed.
  6. So these unreferenced objects should be removed from memory, Then the other new objects you create can find a place in the heap.
  7. The releasing of unreferenced objects is happening automatically in .Net languages by the garbage collector(GC).
  8. In .Net languages there is a facility that we can call garbage collector(GC) explicitly in the program by calling System.GC.Collect.

Advantage:
  1. Allow us to develop an application without having worry to free memory.
  2. Allocates memory for objects efficiently on the managed heap.
  3. Reclaimes the memory for no longer used objects and keeps the free memory for future allocation.
  4. provides memory safety by making sure that an object cannot use the content of another object.

Explain Garbage Collection in .Net

Download the Android app to get all Government Job Notifications on your Mobile.
Download Now
Important: Please always Check and Confirm the above details with the official Advertisement / Notification.
Previous Post Next Post