Tuesday, February 8, 2011

Dump CCWs and RCWs in a mixed managed/unmanaged process

I have a mixed managed/unmanaged environment (Visual Studio and ReSharper) and I suspect CCW or RCW leak. Is there any way to dump all currently allocated wrappers and identify their source/target? I have WinDbg, SOS & SOSEx, so I can see total number of RCWs and CCWs with !syncblk command. I just want to see objects, so I can call !gcroot on them and otherwise examine suspects.

  • You should be able to use !dumpheap to do this. !dumpheap -stat would let you find the type names (if you don't already know them) and then !dumpheap -type {typename} would give you the individual object addresses which can be passed to !gcroot.

    Ilya Ryzhenkov : I do know how to use !dumpheap, I was asking about CCW & RCW, not about all managed objects. How would I distinguish CCW or RCW from other objects in the dumpheap output?
    Curt Hagenlocher : Use their type names. It's been a long time since I used these, but you should be able to use their type names to restrict the output from !dumpheap by using the -type option -- which also supports wild cards. If you're not sure what their type names are, use -stat to list all types.
    Ilya Ryzhenkov : @Curt, CCWs are not represented as managed object. All RCWs has type of __ComObject.
    Sunny : Ilya, not all RCW has __ComObject in the name. They may have a "normal" name, if some interop assembly is used (created by VS.Net when you reference the COM object).

0 comments:

Post a Comment