May 17, 2006

Debugging tips

Make Object ID

When debugging native code, it's easy to keep track of objects by their addresses. But, with managed code, you don't really have this option. This can make it hard to tell keep track of objects. But, when debugging in Visual Studio, you can right click an object and select "Make Object ID". This will put a number like {1#} after the object. You can do this on as many objects as you want to track.

image

image

You can use object ID:

  • to watch particular object in memory, no matter where it goes.
  • allows you to watch objects even out of scope
  • “Can’t evaluate” means object has been GCed
  • Use to find in what GC Generation is particular object

Finding Generation for particular object

You can use GC.GetGeneration to find the generation of particular object. Either you can use object itself or Object ID to find generation in the watch window.

image

Using .NET reference source code

You can debug MS assemblies by downloading the pdb files.

Check http://referencesource.microsoft.com/