Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

WeakReference Constructor (Object, Boolean)

Initializes a new instance of the WeakReference class, referencing the specified object and using the specified resurrection tracking.

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

public WeakReference(
	Object target,
	bool trackResurrection
)

Parameters

target
Type: System.Object

An object to track.

trackResurrection
Type: System.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.

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

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));
 }

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

XNA Framework

Supported in: 3.0, 2.0, 1.0

Portable Class Library

Supported in: Portable Class Library

Supported in: Windows Phone 8.1

Supported in: Windows Phone Silverlight 8.1

Supported in: Windows Phone Silverlight 8
Show:
© 2015 Microsoft