WeakReference Class
Assembly: mscorlib (in mscorlib.dll)
[SerializableAttribute] [ComVisibleAttribute(true)] public ref class WeakReference : ISerializable
/** @attribute SerializableAttribute() */ /** @attribute ComVisibleAttribute(true) */ public class WeakReference implements ISerializable
SerializableAttribute ComVisibleAttribute(true) public class WeakReference implements ISerializable
Not applicable.
A weak reference allows the garbage collector to collect an object while still allowing an application to access the object. If you need the object, you can still obtain a strong reference to it and prevent it from being collected. For more information about how to use short and long weak references, see Using Weak References.
The following example demonstrates how you can use weak references to maintain a cache of objects as a resource for an application. The cache is constructed using an IDictionary of WeakReference objects keyed by an index value. The Target property for the WeakReference objects is an object in a byte array that represents data.
The example randomly accesses objects in the cache. If an object is reclaimed for garbage collection, a new data object is regenerated; otherwise, the object is available to access because of the weak reference.
- SecurityPermission for the ability to call unmanaged code. Demand value: InheritanceDemand; Permission value: UnmanagedCode
Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.