WeakReference WeakReference WeakReference WeakReference Constructors

定义

重载

WeakReference() WeakReference() WeakReference()
WeakReference(Object) WeakReference(Object) WeakReference(Object) WeakReference(Object)

引用指定的对象初始化 WeakReference 类的新实例。Initializes a new instance of the WeakReference class, referencing the specified object.

WeakReference(Object, Boolean) WeakReference(Object, Boolean) WeakReference(Object, Boolean) WeakReference(Object, Boolean)

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

WeakReference(SerializationInfo, StreamingContext) WeakReference(SerializationInfo, StreamingContext) WeakReference(SerializationInfo, StreamingContext) WeakReference(SerializationInfo, StreamingContext)

使用从指定的序列化和流对象反序列化的数据,初始化 WeakReference 类的新实例。Initializes a new instance of the WeakReference class, using deserialized data from the specified serialization and stream objects.

WeakReference() WeakReference() WeakReference()

protected:
 WeakReference();
protected WeakReference ();
Protected Sub New ()

WeakReference(Object) WeakReference(Object) WeakReference(Object) WeakReference(Object)

引用指定的对象初始化 WeakReference 类的新实例。Initializes a new instance of the WeakReference class, referencing the specified object.

public:
 WeakReference(System::Object ^ target);
public WeakReference (object target);
new WeakReference : obj -> WeakReference
Public Sub New (target As Object)

参数

target
Object Object Object Object

要跟踪的对象或为 nullThe object to track or null.

注解

此构造函数创建短弱引用到targetThis constructor creates a short weak reference to target.

另请参阅

WeakReference(Object, Boolean) WeakReference(Object, Boolean) WeakReference(Object, Boolean) WeakReference(Object, Boolean)

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

public:
 WeakReference(System::Object ^ target, bool trackResurrection);
public WeakReference (object target, bool trackResurrection);
new WeakReference : obj * bool -> WeakReference
Public Sub New (target As Object, trackResurrection As Boolean)

参数

target
Object Object Object Object

要跟踪的对象。An object to track.

trackResurrection
Boolean Boolean Boolean Boolean

指示何时停止跟踪对象。Indicates when to stop tracking the object. 如果为 true,则在终结后跟踪对象;如果为 false,则仅在终结前跟踪对象。If true, the object is tracked after finalization; if false, the object is only tracked until finalization.

示例

下面的示例创建使用短弱引用的缓存数据对象。The following example creates a cache of data objects with short weak references. 此示例摘自一个更大的示例为提供WeakReference类。This example is part of a larger example provided for the WeakReference class.

 // Add objects with a short weak reference to the cache.
for (int i = 0; i < count; i++) {
     _cache.Add(i, new WeakReference(new Data(i), false));
 }
' Add data objects with a short weak reference to the cache. 
For ctr = 0 To count - 1
    _cache.Add(ctr, New WeakReference(New Data(ctr)))
Next

注解

如果trackResurrectionfalse,创建短弱引用。If trackResurrection is false, a short weak reference is created. 如果trackResurrectiontrue,则将创建长弱引用。If trackResurrection is true, a long weak reference is created.

另请参阅

WeakReference(SerializationInfo, StreamingContext) WeakReference(SerializationInfo, StreamingContext) WeakReference(SerializationInfo, StreamingContext) WeakReference(SerializationInfo, StreamingContext)

使用从指定的序列化和流对象反序列化的数据,初始化 WeakReference 类的新实例。Initializes a new instance of the WeakReference class, using deserialized data from the specified serialization and stream objects.

protected:
 WeakReference(System::Runtime::Serialization::SerializationInfo ^ info, System::Runtime::Serialization::StreamingContext context);
protected WeakReference (System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context);
new WeakReference : System.Runtime.Serialization.SerializationInfo * System.Runtime.Serialization.StreamingContext -> WeakReference
Protected Sub New (info As SerializationInfo, context As StreamingContext)

参数

info
SerializationInfo SerializationInfo SerializationInfo SerializationInfo

保存序列化或反序列化当前的 WeakReference 对象所需的全部数据的对象。An object that holds all the data needed to serialize or deserialize the current WeakReference object.

context
StreamingContext StreamingContext StreamingContext StreamingContext

(保留)描述由 info 指定的序列化流的源和目标。(Reserved) Describes the source and destination of the serialized stream specified by info.

异常

注解

context参数保留,并不当前参与此操作。The context parameter is reserved, and does not currently participate in this operation.

适用于