Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@markryd
Last active August 22, 2016 18:36
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markryd/5632567 to your computer and use it in GitHub Desktop.
Save markryd/5632567 to your computer and use it in GitHub Desktop.
Memory profiling with windbg
  • Start up windbg and attach (F6).
  • Make sure you pick the right version (x86/x64) and run as admin if your app is running as admin.
  • Make sure you have the microsoft symbol servers turned on in Visual Studio -> tools -> options -> debugging -> symbols

Load

.loadby sos clr

Dump the heap

!DumpHeap -stat

Find the biggest type

!DumpHeap -type Foo

Pick an object

!gcroot [address]

Trace the roots to see what is keeping it alive You can use

!dumpobj [address]

To look at the fields of the object if that is helpful. Do this for a few instances so you find old and new ones (Don't forget some are legit). With thanks to @tathamoddie

To look deeper into gcroots, find out which generation your object is in

!GCWhere [address]

Turn on CLR GC notifications

!HandleCLRN 

Enable breaking on a GC collection (in this case gen 2) and continue the debugger

!FindRoots –gen 2 
g

Run the app until GC occurs and the debugger breaks then run

!FindRoots [address]
@Hdesai
Copy link

Hdesai commented Nov 21, 2014

Prefer Debugger Markup Language After loading sos

.prefer_dml 1

@sheastrickland
Copy link

Break on first chance CLR Exception
sxe clr
More handy, break, print exception, show stack
sxe -c "!pe;!clrstack" clr

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment