(FYI: this question is half toric. This is not what I definitely plan to do).
I would like to be able to store a link to all the objects that I create. Maybe like this:
class Foo { private static List<Foo> AllMyFoos = new List<Foo>(); public Foo() { AllMyFoos.Add(this); } }
The problem is that now none of my Foos can fall out of focus and collect trash. Is there a way to keep the link without interfering with the garbage collector?
Ideally, I'm just a list of Foos that are still in use, and not all Foos that have ever been used.
source share