📁 Sangam Dhakal - Portfolio v2.0 - Netscape Navigator 4.0
_
□
×

📚 Interview question

How do you tell a managed memory leak from native memory growth in a .NET process?

Separating managed heap growth from native memory growth in a .NET process, and the tools for each.

Senior Theory Advanced dotnet-counters dotnet-dump memory-leak native-memory production

🎯 Key points

  • Compare gc-heap-size with working set / committed memory
  • Managed heap rising -> gcdump diff and gcroot
  • Heap flat, working set rising -> native allocations
  • !eeheap is managed only; use !maddress and native profilers for native
  • Check handle and thread counts for handle leaks
  • Watch the impact: GC time and p99 latency rise before OOM

⏱ 30-second answer

Compare the managed heap with the process memory. dotnet-counters gives gc-heap-size and working-set; if both rise together, it's a managed leak: diff two dotnet-gcdump snapshots and follow gcroot in dotnet-dump. If the working set (or private/committed memory) climbs while the GC heap stays flat, the growth is native: undisposed native handles, unmanaged buffers (NativeMemory, Marshal.AllocHGlobal), a native library, or many thread stacks. In a dump, !eeheap -gc only covers the managed heap; for native use !maddress -summary (address-space breakdown), watch handle and thread counts (/proc/<pid>/fd, Task Manager, !threads), and use native profilers (WinDbg/!heap on Windows, heaptrack or valgrind on Linux). Also watch the effect: rising memory usually shows up as more GC time and higher p99 before the OOM.

🔍 What the interviewer is checking

Checks they can separate GC heap growth from unmanaged allocations.

↩ Usually asked after

More in Debugging Production Issues

Last updated 23 Nov 2026.

🌐 Sangam's Webring

⏪ Previous 🏠 Main Next ⏩
💬 Chat with me