Hi. I am refactoring an application and I am in the process of adding cleanup
code. I am trying to dereference objects that are no longer required, but I
am finding that references are held in other parts of the application and the
object is consequently never collected.
Is there anyway to enumerate ALL references to a particular object instance
(either in code or interactively)? The GC can do it, so I am hoping I can too.
Thanks
kh
Jon Skeet [C# MVP] - 31 Dec 2004 12:43 GMT
> Hi. I am refactoring an application and I am in the process of adding cleanup
> code. I am trying to dereference objects that are no longer required, but I
[quoted text clipped - 3 lines]
> Is there anyway to enumerate ALL references to a particular object instance
> (either in code or interactively)? The GC can do it, so I am hoping I can too.
No - even the GC doesn't do it. It doesn't find all references to any
particular object, it just finds all objects which have live
references.
Profilers can do this, however. Unfortunately I don't have any
particular recommendations in terms of profilers.

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
David Levine - 31 Dec 2004 17:35 GMT
As Jon pointed out there is no builtin mechanism for this; code inspection
might help here. One thing that can unintentionally cause references to
remain live are subscriptions to events that are never unsubscribed as the
event itself holds a reference to the subscriber. Other things to look at
are static fields that hold references to objects.
I'd run your app under a memory profiler and look at what's on the managed
heap. There are several free ones; I don't have links but it should be easy
enough to google some up.
> Hi. I am refactoring an application and I am in the process of adding
> cleanup
[quoted text clipped - 12 lines]
>
> kh