WeakReference WeakReference WeakReference WeakReference Constructors

Definition

Overloads

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

Initializes a new instance of the WeakReference class, referencing the specified object.

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

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)

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)

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)

Parameters

target
Object Object Object Object

The object to track or null.

Remarks

This constructor creates a short weak reference to target.

See also

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

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)

Parameters

target
Object Object Object Object

An object to track.

trackResurrection
Boolean Boolean Boolean Boolean

Indicates when to stop tracking the object. If true, the object is tracked after finalization; if false, the object is only tracked until finalization.

Examples

The following example creates a cache of data objects with short weak references. 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

Remarks

If trackResurrection is false, a short weak reference is created. If trackResurrection is true, a long weak reference is created.

See also

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

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)

Parameters

info
SerializationInfo SerializationInfo SerializationInfo SerializationInfo

An object that holds all the data needed to serialize or deserialize the current WeakReference object.

context
StreamingContext StreamingContext StreamingContext StreamingContext

(Reserved) Describes the source and destination of the serialized stream specified by info.

Exceptions

Remarks

The context parameter is reserved, and does not currently participate in this operation.

Applies to