.NET › Diagnostics & Performance
How does the dotnet-gcdump tool help diagnose managed memory leaks, and how do you analyze the resulting heap snapshot?
AdvancedAnswer
dotnet-gcdump collects a snapshot of the entire managed heap from a running process (triggering a full GC first to ensure only genuinely reachable objects are captured), producing a .gcdump file that can be analyzed in Visual Studio's memory analysis tools or PerfView to see object counts and retained sizes by type, and critically, trace the reference paths keeping unexpectedly numerous or large objects alive -- essential for finding the root cause of a managed memory leak (as opposed to unmanaged memory growth, which requires different tools).
dotnet tool install -g dotnet-gcdump
dotnet-gcdump collect --process-id 1234
# Analyze the resulting .gcdump in Visual Studio: Debug > Windows > Show Diagnostic Tools > Memory UsageReal-world example A service exhibiting slow but steady memory growth over days captures two gcdump snapshots hours apart, comparing them to identify a specific cache dictionary that was never evicting old entries, growing unbounded.