Compartilhar via


Make Object ID

Command:  DebuggerContextMenus.AutosWindow.MakeObjectID
Versions:  2008,2010
Published:  3/4/2010
Code:  vstipDebug0015

 

Ever want to track an object even if it is out of scope?  How about see if an object has been garbage collected?  Well, you can do it with the Object ID!  And how do you get one of these amazing things?  Simple, just follow these steps:

 

  1. Set a BreakPoint in your code where you can get to an object variable that is in scope.

  2. Run your code and let it stop at the BreakPoint.

  3. In your Locals or Autos Window, right-click the object variable (note the Value column) and choose "Make Object ID" from the context menu.
     image

  4. You should now see something new in the Value column:
    image

  5. That new value is the Object ID that was generated.  Let's see how it works.

  6. Put the object variable and the new Object ID in your Watch Window:
    image

  7. Now if I go to another method where the object variable (in this case "doc") is out of scope this is the result:
    image

If you want to learn more about Object ID then I suggest you see John Robbin's blog post here:

https://www.wintellect.com/CS/blogs/jrobbins/archive/2008/04/18/finding-an-object-s-gc-generation-in-the-visual-studio-debugger.aspx

Comments

  • Anonymous
    August 09, 2010
    Great! I never knew that exists, I've been eagerly looking for it!!

  • Anonymous
    July 04, 2011
    Thanks a lot! A great future feature in visual studio's watches, would be the option "Run until watch changed" or a conditional on the watch.

  • Anonymous
    March 12, 2012
    Do "Make Object ID" adds a reference to the object? If so will it have any effect in GC?

  • Anonymous
    March 12, 2012
    Paras, Not in the way you are used to.  The reference it makes never goes out of scope so, unlike a traditional reference, you can view ObjectID information as long as the object is in memory.  It has no impact on collection and doesn't count as a reference for keeping the object in memory. Z