Workstation GC vs Server GC
Context: .NET offers two GC modes optimized for different application types. Workstation GC is designed for client applications (WPF, WinForms, Console) where UI responsiveness is critical; it uses a single GC thread and prefers lower latency. Server GC is for server applications (ASP.NET, services) that need high throughput and scalability; it creates one GC thread per CPU core and collects heaps in parallel.
| Mode | Usage | Characteristics |
|---|---|---|
| Workstation GC | Client apps | Single GC thread, optimized for low latency |
| Server GC | Server apps | Multiple GC threads, optimized for throughput |
Usage Example
Section titled “Usage Example”<!-- Configuration in .csproj or runtimeconfig.json --><PropertyGroup> <ServerGarbageCollection>true</ServerGarbageCollection></PropertyGroup>// Check current modeusing System;using System.Runtime;
Console.WriteLine($"GC mode: {(GCSettings.IsServerGC ? "Server" : "Workstation")}");Output console
Section titled “Output console”dotnet runGC mode: WorkstationImportant notes
Section titled “Important notes”- Workstation is the default for client applications.
- Server is recommended for backend applications with many threads and high memory allocation.
Real‑world usage example
Section titled “Real‑world usage example”ASP.NET Core web API – By default, it runs on Server GC to handle many concurrent requests efficiently. You can override this in the project file.
See .NET docs on GC modes.