Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
WeakReference(T) Class
Collapse the table of content
Expand the table of content

WeakReference<T> Class

.NET Framework 4.6 and 4.5

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

System.Object
  System.WeakReference<T>

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

[SerializableAttribute]
public sealed class WeakReference<T> : ISerializable 
where T : class

Type Parameters

T

The type of the object referenced.

The WeakReference<T> type exposes the following members.

  NameDescription
Public methodWeakReference<T>(T)Initializes a new instance of the WeakReference<T> class that references the specified object.
Public methodWeakReference<T>(T, Boolean)Initializes a new instance of the WeakReference<T> class that references the specified object and uses the specified resurrection tracking.
Top

  NameDescription
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected methodFinalizeDiscards the reference to the target that is represented by the current WeakReference<T> object. (Overrides Object.Finalize().)
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetObjectDataPopulates a SerializationInfo object with all the data necessary to serialize the current WeakReference<T> object.
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodSetTargetSets the target object that is referenced by this WeakReference<T> object.
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Public methodTryGetTargetTries to retrieve the target object that is referenced by the current WeakReference<T> object.
Top

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.

.NET Framework

Supported in: 4.6, 4.5

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone Silverlight 8.1, Windows Phone Silverlight 8

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show:
© 2015 Microsoft