WeakReference<T> Class

Definition

Represents a typed weak reference, which references an object while still allowing that object to be reclaimed by garbage collection.

public sealed class WeakReference<T> where T : class
public sealed class WeakReference<T> : System.Runtime.Serialization.ISerializable where T : class
[System.Serializable]
public sealed class WeakReference<T> : System.Runtime.Serialization.ISerializable where T : class

Type Parameters

T

The type of the object referenced.

Inheritance
WeakReference<T>
Attributes
Implements

Remarks

A weak reference enables the garbage collector to collect an object while still allowing an application to access the object. If you need the object, you can obtain a strong reference to it and prevent it from being collected.

Constructors

WeakReference<T>(T, Boolean)

Initializes a new instance of the WeakReference<T> class that references the specified object and uses the specified resurrection tracking.

WeakReference<T>(T)

Initializes a new instance of the WeakReference<T> class that references the specified object.

Methods

Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
Finalize()

Discards the reference to the target that is represented by the current WeakReference<T> object.

GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetObjectData(SerializationInfo, StreamingContext)
Obsolete.

Populates a SerializationInfo object with all the data necessary to serialize the current WeakReference<T> object.

GetType()

Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
SetTarget(T)

Sets the target object that is referenced by this WeakReference<T> object.

ToString()

Returns a string that represents the current object.

(Inherited from Object)
TryGetTarget(T)

Tries to retrieve the target object that is referenced by the current WeakReference<T> object.

Applies to

Produkt Verze
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6, 2.0, 2.1
UWP 10.0