I’m trying to fix on an old, clunky, complicated legacy system with a memory leak. I’ve traced the problem back and the best way to describe the memory leak is that it’s “by design.” In simple terms, there is an event observer that is holding a reference to objects after they’ve been abandoned. For this reason objects can’t be collected by the garbage collector and stay in memory indefinitely.
Is there a way to get a collection of objects that currently hold a reference to an instance?
You could try getting technical by using WinDbg with the Sosex extension DLL. If you’re not familiar with WinDbg then try reading Tess Ferrandez’s blog which is a goldmine of .NET debugging information.
Basically, Sosex.dll has a
!Refscommand which lists objects that have a reference to a specific object address you give. For example:Please note that this is a very hardcore solution, which will require a fair bit of preparation if you;re new to this. However, it can be a very powerful way to debug .NET apps.