The garbage collector (GC) is a part of the .NET framework which is initialized by the common language run-time (CLR) to manage the allocation and release of memory in an application.

Types of garbage collector

The garbage collector can work in a wide variety of scenarios. The CLR provides the following types of garbage collection:

  • Workstation garbage collection (GC) runs on the normal priority thread, can be concurrent or non-concurrent, and is designed for client apps
  • Server garbage collection is designed for server applications and creates a separate managed heap and a corresponding garbage collection thread for each logical CPU. Threads run on highest priority making it faster but more resource intensive. In .NET Core, .NET Framework 4.5 and later versions server garbage collection can be non-concurrent or background. In .NET Framework 4 and previous versions, server garbage collection is non-concurrent.

Concurrent garbage collection

Concurrent garbage collection allows user threads to run for the most of generation 2 garbage collection. As long as there is still free space in the managed heap for new allocations, user threads are allowed to run and create new objects.

Image for post

Non-concurrent garbage collection

Non-concurrent garbage collection suspends all non-garbage-collection threads for the full duration of the garbage collection, effectively pausing the application for that time.

#coding #csharp #software-engineering #dotnet #garbage-collection #visual studio code

What is a garbage collector?
1.45 GEEK