Windows apps
Collapse the table of content
Expand the table of content
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

WeakReference Class1


The new home for Visual Studio documentation is Visual Studio 2017 Documentation on

The latest version of this topic can be found at WeakReference Class1.

Supports the WRL infrastructure and is not intended to be used directly from your code.

class WeakReference;  

Represents a weak reference that can be used with the Windows Runtime or classic COM. A weak reference represents an object that might or might not be accessible.

A WeakReference object maintains a strong reference, which is a pointer to an object, and a strong reference count, which is the number of copies of the strong reference that have been distributed by the Resolve() method. While the strong reference count is nonzero, the strong reference is valid and the object is accessible. When the strong reference count becomes zero, the strong reference is invalid and the object is inaccessible.

A WeakReference object is typically used to represent an object whose existence is controlled by an external thread or application. For example, construct a WeakReference object from a reference to a file object. While the file is open, the strong reference is valid. But if the file is closed, the strong reference becomes invalid.

The WeakReference methods are thread safe.

Public Constructors

WeakReference::WeakReference ConstructorInitializes a new instance of the WeakReference class.
WeakReference::~WeakReference DestructorDeinitializes (destroys) the current instance of the WeakReference class.

Public Methods

WeakReference::DecrementStrongReference MethodDecrements the strong reference count of the current WeakReference object.
WeakReference::IncrementStrongReference MethodIncrements the strong reference count of the current WeakReference object.
WeakReference::Resolve MethodSets the specified pointer to the current strong reference value if the strong reference count is nonzero.
WeakReference::SetUnknown MethodSets the strong reference of the current WeakReference object to the specified interface pointer.


Header: implements.h

Namespace: Microsoft::WRL::Details

Microsoft::WRL::Details Namespace

© 2017 Microsoft