What is a garbage collector?

Garbage collector feature in .NET frees the unused code objects in the memory. The memory head is divided into 3 generations:

  • Generation 0: It stores short-lived objects.
  • Generation 1: This is for medium-lived objects.
  • Generation 2: It stores long-lived objects.
    Collection of garbage refers to the collection of objects stored in the generations.