[Serializable] |
Garbage collection will call an object's Object.Finalize method (that is, perform finalization), if there is such a method and if instructed to do so. Once finalization is complete, unpredictable results will occur if the garbage collected object is reacquired somehow and reused.
A directly or indirectly referenced object is reachable, and the garbage collector is not permitted to reclaim it. A reference to a reachable object is called a strong reference.
A weak reference also references a reachable object, which is called the target. A user acquires a strong reference to the target by assigning the value of the WeakReference.Target property to a variable. However, if there are no strong references to the target, the target becomes eligible for garbage collection even though it still has a weak reference.
There can be a delay between the time an object becomes eligible for garbage collection and the time it is collected. If the user attempts to retrieve the target after it has been collected, only a null reference will be retrieved. If the target has not yet been collected, a valid reference will be retrieved.
An object can be used (that is, be alive); become unused and eligible for garbage collection (that is, dead); then used again (that is, resurrected). However, unpredictable behavior results if a resurrected object is accessed after finalization.
A WeakReference object can specify whether the reference to its target be maintained after finalization; that is, whether the weak reference should track the target's resurrection. A weak reference that does not track resurrection is called a short weak reference, and a weak reference that tracks resurrection is called a long weak reference.
ctor #1 | Overloaded:.ctor(object target) Initializes a new instance of the WeakReference class, referencing the specified object. |
ctor #2 | Overloaded:.ctor(object target, bool trackResurrection) Initializes a new instance of the WeakReference class, referencing the specified object and using the specified resurrection tracking. |
IsAlive | Read-only Gets an indication whether the object referenced by this instance has been garbage collected. |
Target | Read-write Gets or sets the object (the target) referenced by this instance. |
TrackResurrection | Read-only Gets an indication whether the object referenced by this instance is tracked after it is garbage collected and finalized. |
Equals (inherited from System.Object) |
See base class member description: System.Object.Equals Derived from System.Object, the primary base class for all objects. |
GetHashCode (inherited from System.Object) |
See base class member description: System.Object.GetHashCode Derived from System.Object, the primary base class for all objects. |
GetObjectData | Populates a SerializationInfo object with all the data needed to serialize this instance. |
GetType (inherited from System.Object) |
See base class member description: System.Object.GetType Derived from System.Object, the primary base class for all objects. |
ToString (inherited from System.Object) |
See base class member description: System.Object.ToString Derived from System.Object, the primary base class for all objects. |
ctor #3 | Overloaded:.ctor(SerializationInfo info, StreamingContext context) Initializes a new instance of the WeakReference class, using deserialized data from the specified serialization and stream objects. |
Finalize | Overridden: Frees any resources allocated by this instance. |
MemberwiseClone (inherited from System.Object) |
See base class member description: System.Object.MemberwiseClone Derived from System.Object, the primary base class for all objects. |
Hierarchy:
public WeakReference( |
target
target
trackResurrection
protected WeakReference( |
info
context
Exception Type | Condition |
---|---|
ArgumentNullException | info is null. |
public virtual bool IsAlive {get;}
|
Exception Type | Condition |
---|---|
InvalidOperationException | The reference to the target object is invalid. |
public virtual object Target {get; set;}
|
Exception Type | Condition |
---|---|
InvalidOperationException | The reference to the target object is invalid. |
public virtual bool TrackResurrection {get;}
|
~WeakReference(); |
public virtual int GetHashCode(); |
public virtual void GetObjectData( |
info
context
Exception Type | Condition |
---|---|
ArgumentNullException | info is null. |
The context parameter is reserved and is not currently used in the execution of this method.
public Type GetType(); |
protected object MemberwiseClone(); |
public virtual string ToString(); |