Represents a weak reference, which references an object while still allowing that object to be reclaimed by garbage collection.
Assembly: mscorlib (in mscorlib.dll)
Initializes a new instance of theclass, referencing the specified object.
Initializes a new instance of theclass, referencing the specified object and using the specified resurrection tracking.
Initializes a new instance of theclass, using deserialized data from the specified serialization and stream objects.
Gets an indication whether the object referenced by the currentobject has been garbage collected.
Gets or sets the object (the target) referenced by the currentobject.
Gets an indication whether the object referenced by the currentobject is tracked after it is finalized.
Determines whether the specified object is equal to the current object.(Inherited from Object.)
Discards the reference to the target represented by the current Object::Finalize().)object.(Overrides
Serves as the default hash function. (Inherited from Object.)
Populates a SerializationInfo object with all the data needed to serialize the current object.
Returns a string that represents the current object.(Inherited from Object.)
A weak reference allows the garbage collector to collect an object while still allowing an application to access the object. If you need the object, you can still obtain a strong reference to it and prevent it from being collected. For more information about how to use short and long weak references, see Weak References.
The following example demonstrates how you can use weak references to maintain a cache of objects as a resource for an application. The cache is constructed using an IDictionary<TKey, TValue> of objects keyed by an index value. The Target property for the objects is an object in a byte array that represents data.
The example randomly accesses objects in the cache. If an object is reclaimed for garbage collection, a new data object is regenerated; otherwise, the object is available to access because of the weak reference.
Available since 8
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Available since 8.1
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.