WeakReferences And Tracking Resurrection
The WeakReference class has two public constructors.
public WeakReference(Object target)
public WeakReference(Object target, bool trackResurrection)
The first parameter is pretty obvious. It’s the object you want the WeakReference to reference, without keeping the object alive. If a WeakReference is the only thing referencing an object, then the GC is free to collect the object. After the GC collects the object, WeakReference.IsAlive will return false, and WeakReference.Target will return null. The WeakReference loses its handle to the object as soon as the GC collects it but before the finalizer (if any) gets run. This is called a short WeakReference.
If the caller passes true as the trackResurrection parameter, then the WeakReference tracks the object’s life until finalization is complete. This is called a long WeakReference. If the object is resurrected, a long WeakReference will continue to reference it, where a short WeakReference will report it as dead.
The same distinction also applies to GCHandleType.Weak.
Comments
- Anonymous
October 11, 2007
Weak references is a feature where one object can point to another without holding it. In other words, - Anonymous
October 11, 2007
PingBack from http://msdnrss.thecoderblogs.com/2007/10/11/is-weakreference-a-weak-feature/ - Anonymous
November 25, 2007
PingBack from http://feeds.maxblog.eu/item_191467.html