Is it possible to implement a GC.GetAliveInstancesOf<T>() (for use in debugging)?

Posted by Omer Raviv on Stack Overflow See other posts from Stack Overflow or by Omer Raviv
Published on 2010-06-06T21:21:53Z Indexed on 2010/06/06 21:32 UTC
Read the original article Hit count: 450

Filed under:
|
|
|
|

Hi,

I know this was answered before, but I'd like to pose a somewhat different question.

Is there any conceivable way to implement GC.GetAliveInstancesOf(), that can be evaluated in Visual Studio Debug Watch window? Sasha Goldstein shows one solution in this article, but it requires every class you want to query inherit from a specific base class.

I'll emphasize that I only want to use this method during debugging, so I don't care that the GC may change an object's address in memory during runtime.

One idea might be to somehow harness the !dumpheap –type command of SOS, and do some magic trick to create a temporary variable and have it point out to the memory address printed by SOS.

Does anyone have a solution that works?

© Stack Overflow or respective owner

Related posts about visual-studio

Related posts about debugging