WeakReference<T> 类

定义

表示类型化弱引用,即在引用对象的同时仍然允许垃圾回收来回收该对象。Represents a typed weak reference, which references an object while still allowing that object to be reclaimed by garbage collection.

generic <typename T>
 where T : classpublic ref class WeakReference sealed : System::Runtime::Serialization::ISerializable
[System.Serializable]
public sealed class WeakReference<T> : System.Runtime.Serialization.ISerializable where T : class
type WeakReference<'T (requires 'T : null)> = class
    interface ISerializable
Public NotInheritable Class WeakReference(Of T)
Implements ISerializable

类型参数

T

所引用对象的类型。The type of the object referenced.

继承
WeakReference<T>
属性
实现

注解

弱引用使垃圾回收器可以收集对象,同时仍然允许应用程序访问对象。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.

构造函数

WeakReference<T>(T)

初始化引用指定对象的 WeakReference<T> 类的新实例。Initializes a new instance of the WeakReference<T> class that references the specified object.

WeakReference<T>(T, Boolean)

初始化 WeakReference<T> 类的新实例,该类引用指定的对象并使用指定的复活跟踪。Initializes a new instance of the WeakReference<T> class that references the specified object and uses the specified resurrection tracking.

方法

Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
Finalize()

丢弃对当前 WeakReference<T> 对象表示的目标的引用。Discards the reference to the target that is represented by the current WeakReference<T> object.

GetHashCode()

用作默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetObjectData(SerializationInfo, StreamingContext)

用序列化当前 SerializationInfo 对象所需的所有数据填充 WeakReference<T> 对象。Populates a SerializationInfo object with all the data necessary to serialize the current WeakReference<T> object.

GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
SetTarget(T)

设置 WeakReference<T> 对象引用的目标对象。Sets the target object that is referenced by this WeakReference<T> object.

ToString()

返回一个表示当前对象的 string。Returns a string that represents the current object.

(继承自 Object)
TryGetTarget(T)

尝试检索当前 WeakReference<T> 对象引用的目标对象。Tries to retrieve the target object that is referenced by the current WeakReference<T> object.

适用于