Find all references

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
kh said:
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.

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.
 
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.
 
Back
Top