5

How can I analyze the unmanaged heap size of a .NET process with Windbg? Which commands should be used in WinDbg?

Thomas Weller
  • 43,638
  • 16
  • 101
  • 185
mkus
  • 3,007
  • 5
  • 32
  • 43
  • 1
    Can you elaborate more, what do you want to know, size, usage, %free etc... Does `!address -summary` give you what you want or do you need something more like `!heap -s` or `!heap -stat`? – EdChum Jan 28 '14 at 08:45
  • I want to learn just the size of unmanaged memory size. !address - summary gives something but I don't understand what the output says. – mkus Jan 28 '14 at 09:42

1 Answers1

14

!address -summary gives you an overview not focusing on individuals heaps.

Usage summary contains the following:

  • Free: free memory which can be allocated ans used
  • Image: memory used by EXE and DLL files
  • MappedFile: memory used by memory mapped files
  • Heap / Heap32 / Heap64: memory allocated via the heap manager
  • Stack / Stack32 / Stack 64: memory used by stacks of threads
  • TEB / TEB32 / TEB64: memory used by thread environment blocks
  • PEB / PEB32 / PEB64: memory used by process environment blocks (e.g. command line and environment variables)

Type summary contains:

  • MEM_IMAGE: should roughly correspond to Image
  • MEM_MAPPED: should roughly correspond to MappedFile
  • MEM_PRIVATE: private memory which can only be used by your application and not be shared

State summary:

  • MEM_FREE: should roughly correspond to Free
  • MEM_COMMIT: memory in use
  • MEM_RESERVE: memory which might be used

Protect Summary should explain itself. If you're very new, it's probably not that interesting.

Largest Region by usage:

Especially important here is the free region. The largest free region determines how much memory you can get in one block. Look around for memory fragmentation to find out why this can be an issue.

!heap -s gives you the summary about heaps with focus on individual heaps.

These are all native memory allocations done via the Windows heap manager. Direct allocations via VirtualAlloc() are not listed (e.g. MSXML and .NET).

Read more about native memory management on MSDN: Managing Heap Memory and MSDN: Managing Virtual Memory

Community
  • 1
  • 1
Thomas Weller
  • 43,638
  • 16
  • 101
  • 185