18 June 2023

C# - Choosing a GC mode

There is a lot more to the following answer, so I will do a followup blog that includes heavier testing, but the TLDR is:

To set it, you configure it in your .csproj file

<PropertyGroup>
    ...
    <ServerGarbageCollection>false</ServerGarbageCollection>
    <ConcurrentGarbageCollection>true</ConcurrentGarbageCollection>
</PropertyGroup>

Where turning ServerGarbageCollection to false will give it the workstation GC.

In practice, for a very minimal API, the difference was 180MB on Server and 66MB on Workstation inside a Docker container.

tags: c# - garbage collector