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:


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

Comments (8)

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

  2. gOODiDEA.NET says:

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

  3. gOODiDEA says:


  4. Josh Coswell says:

    Very helpfull.

    Thanks much.

    Josh Coswell

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

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

  7. alonesword says:

    i can't find these commands since 2.0. just only in clr10sos.dll . how to find the object reference to the objaddress ,such as !gcref.

  8. You are right that this isn't in the 2.0 version yet.  But there is a release we are working on that will have this in it.  I will post when it is available and where you can get it from.

Skip to main content