I am looking for a managed/unmanaged API that will allow me to find which objects reference another object and are potentially keeping it from being garbage collected.
Such an API might look like this:
var foo = new Foo();
var bar = new Bar();
bar.Foo = foo;
var references = GC.GetReferencesTo(foo);
// references is an array that contains bar
I know profilers can be used for this but I'd like to make it part of a unit test. Is there a managed or unmanaged API that I could use?