ASP.NET Tips: Debugger command you may not know about - gcref

During the course of debugging, often times you will find an object that you would like to know where it came from (who allocated the object).  The first command you will want to run is !gcroot.  But this command will only find the object if it is rooted on a thread or a global currently.  If the object tree is no longer rooted anywhere, then you won't get any results since the object is ready to be collected by the GC.

But there may be other objects that haven't been collected by the GC that hold onto a reference to this object.  This is where !gcref comes in.  This command will print all the parents and children of the given object.  Because we aren't going top down, we can't print the entire tree of parents.

The output looks like:

gcref

One switch that is useful to use with this command is the -objectonly switch.  The reason for this is without the switch, !gcref will cache all the parents and children of all objects in the heap.  If you have a larger dump, that could be a lot of memory and it is possible to run out of memory in the debugger.  So this switch will just look for the one object you are asking for and nothing else.

kick it on DotNetKicks.com

Published 03 April 08 11:22 by Tom

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# DotNetKicks.com said on April 4, 2008 10:57 AM:

You've been kicked (a good thing) - Trackback from DotNetKicks.com

# gOODiDEA.NET said on April 4, 2008 11:17 PM:

.NET Framework Design Studio Published Counting Processors in .NET: The Pros and Cons of Five Different

# gOODiDEA said on April 4, 2008 11:19 PM:

.NETFrameworkDesignStudioPublishedCountingProcessorsin.NET:TheProsandConsofFiveDif...

# Josh Coswell said on April 5, 2008 9:32 PM:

Very helpfull.

Thanks much.

Josh Coswell

http://riverasp.net

# Community Blogs said on April 9, 2008 2:39 AM:

Silverlight: Silverlight Roadmap questions Ashish Thapliyal Third Silverlight v1.0 Servicing Release

# ASP.NET Debugging said on June 18, 2008 3:46 PM:

These are not a new command in some regards as they were added to the 1.x version of SOS that ships with

Leave a Comment

(required) 
(optional)
(required) 

Search

Go

This Blog

Syndication

Page view tracker