Skip to main content
InterviewHubPRO
Section Overview
Q39

Question 39 of 50

Part 3: CLR Internals, Native AOT & Production Diagnostics (25 - 35)

78%
C# & CLR Internals (50 Qs)•Part 3: CLR Internals, Native AOT & Production Diagnostics (25 - 35)

.NET Garbage Collection: Generational GC and the Large Object Heap (LOH).

senior LevelMemory ManagementData Structures

In Simple Words: The .NET CLR uses a generational tracing garbage collector:

  1. Gen 0: Freshly allocated short-lived objects (collected in sub-milliseconds).
  2. Gen 1: Buffer generation acting as a ramp between short-lived and long-lived data.
  3. Gen 2: Long-lived objects (static caches, database connection pools).
  4. Large Object Heap (LOH): Objects $\ge 85,000\text{ bytes}$ (such as large arrays). LOH objects bypass Gen 0/1 and are allocated directly in Gen 2; historically not compacted, risking memory fragmentation (use GCSettings.LargeObjectHeapCompactionMode to compact).
  5. Server GC: Spawns one GC thread and dedicated managed heap per logical CPU core for massive multi-threaded web servers.