How to analyze unmanaged heap size of a .NET process
Asked Answered
L

1

6

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

Lashawna answered 28/1, 2014 at 8:2 Comment(2)
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?Smoothbore
I want to learn just the size of unmanaged memory size. !address - summary gives something but I don't understand what the output says.Lashawna
F
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

Flagstad answered 28/1, 2014 at 11:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.