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.
Comments
Anonymous
April 04, 2008
You've been kicked (a good thing) - Trackback from DotNetKicks.comAnonymous
April 04, 2008
.NET Framework Design Studio Published Counting Processors in .NET: The Pros and Cons of Five DifferentAnonymous
April 04, 2008
.NETFrameworkDesignStudioPublishedCountingProcessorsin.NET:TheProsandConsofFiveDif...Anonymous
April 05, 2008
Very helpfull. Thanks much. Josh Coswell http://riverasp.netAnonymous
April 08, 2008
Silverlight: Silverlight Roadmap questions Ashish Thapliyal Third Silverlight v1.0 Servicing ReleaseAnonymous
June 18, 2008
These are not a new command in some regards as they were added to the 1.x version of SOS that ships withAnonymous
December 27, 2009
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.Anonymous
December 30, 2009
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.