Supports a weak reference.
Object
WeakReference
[Visual Basic] Public Class WeakReference Implements ISerializable [C#] public class WeakReference : ISerializable [C++] public __gc class WeakReference : public ISerializable [JScript] public class WeakReference implements ISerializable
The WeakReference class is a wrapper for establishing a weak reference to an Object.
The garabage collector (GC) tracks all references to objects in the runtime. It collects and frees only objects that are not referenced by other objects.
Tracking ensures that references to objects are invalid. However, it does pose a problem. It is not possible to hold a refernce only as long as another object is holding it as well. For example, you may want to store objects in a collection, but not keep them alive only becuase they are a collection.
The WeakReference class solves this problem. Objects referenced through the WeakReference class are kep alive only as long as there are at least one strong (that is, normal) reference to the object. The Execution Engine (EE) supports two styles of weak reference:
The distinction between the two is whether the reference is zeroed before or after finalization of the target object. The constructor for WeakReference takes a Boolean named trackResurrection and determines which of the two styles to use. By default the trackResurrection is set to false, so that the object is tracked only until finalization (that is, the object was zeroed before finalization). Note: Constant strings may be pooled by the runtime. Therefore, weak references to constant strings may live fo the life of the runtime.
Namespace: System
Assembly: mscorlib.dll
WeakReference Members | System Namespace | GCHandle | GC | System.Runtime