.NET › Diagnostics & Performance
What is a memory dump, and how do you capture and analyze one for a .NET application experiencing high memory usage or a crash?
IntermediateAnswer
A memory dump is a complete snapshot of a process's memory at a point in time, capturable via dotnet-dump collect (for live processes) or automatically on crash (via configuration), then analyzed using dotnet-dump analyze's SOS debugger commands (like `dumpheap -stat` to see object counts by type) or loaded into Visual Studio/WinDbg for deeper investigation -- essential for post-mortem analysis of crashes or diagnosing memory issues that are hard to reproduce outside production.
dotnet tool install -g dotnet-dump
dotnet-dump collect --process-id 1234
dotnet-dump analyze core_20240115.dmp
# Inside the analyze REPL:
> dumpheap -stat
# Shows object counts and total size by type, sorted by total sizeReal-world example A production crash investigation captures a dump automatically via a crash handler configuration, and a subsequent dotnet-dump analyze session reveals an unexpectedly massive number of retained HttpClient instances, pointing to a resource leak from not reusing HttpClient properly.