Understanding long and short weak references
In the .NET runtime, there are two types of references: long weak references and short weak references. These are described in more detail here:
- Long weak reference: When the
Finalize()
method has been called on an object, a long weak reference is retained in memory. You specifytrue
in theWeakReference
constructor to define a long reference. A long weak reference can be recreated, although its state can be unpredictable. A short weak reference will be applied when an object’s type does not have aFinalize()
method. The weak reference will only remain until its target is collected sometime after the finalizer is run. You will need to cast the target property of aWeakReference
constructor to the type of an object if you want to create a strong weak reference that will be reused. When the object is collected, theTarget
property will benull
. If it is notnull
, then you can continue to use the object because the application...