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:
- Set a BreakPoint in your code where you can get to an object variable that is in scope.
- Run your code and let it stop at the BreakPoint.
- In your Locals or Autos Window, right-click the object variable (note the Value column) and choose "Make Object ID" from the context menu.
- You should now see something new in the Value column:
- That new value is the Object ID that was generated. Let's see how it works.
- Put the object variable and the new Object ID in your Watch Window:
- Now if I go to another method where the object variable (in this case "doc") is out of scope this is the result:
If you want to learn more about Object ID then I suggest you see John Robbin's blog post here: