I would like to keep a list of a certain class of objects in my application. But I still want the object to be garbage collected. Can you create weak references in .NET?
For reference:
- Garbage Collecting objects which keep track of their own instances in an internal Map
- Create a weak reference to an object
Answer From MSDN:
To establish a weak reference with an object, you create a WeakReference using the instance of the object to be tracked. You then set the Target property to that object and set the object to null. For a code example, see WeakReference in the class library.