Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to analyze unmanaged heap size of a .NET process

Tags:

windbg

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

like image 464
mkus Avatar asked Jan 28 '14 08:01

mkus


1 Answers

!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

like image 164
Thomas Weller Avatar answered Oct 02 '22 17:10

Thomas Weller