Back to articles
Making .NET GC Behavior Observable: What I Learned Building GCExperiment

Making .NET GC Behavior Observable: What I Learned Building GCExperiment

via Dev.toMehedi Hasan Shuvo

I've been studying .NET GC internals and wanted to go beyond reading docs — so I built a small experiment suite to make the behavior actually visible. This post walks through what I learned and what each experiment demonstrates. The full repo is at the end. Why experiments? Documentation tells you what the GC does. Running code tells you when and why . The difference matters when you're trying to reason about allocation pressure in real systems. The project is called GCExperiment — four isolated experiments, each targeting one GC mechanic, all instrumented with real snapshots. Built on .NET 10 / C# 14, x64 only. Header sizes and alignment differ on x86, so 64-bit is required for realistic LOH behavior. Experiment 1 — LOH Placement The most surprising thing I learned: it's not a simple 85,000-byte threshold. The GC measures the full object cost — header, payload, and alignment. Here's the actual math for byte[84_999] : 24 bytes (array header) + 84,999 (payload) = 85,023 → aligned to 85,

Continue reading on Dev.to

Opens in a new tab

Read Full Article
2 views

Related Articles