Releasing WinRT Runtime Classes

Rebeka Fox 106 Reputation points

As I understand it, all references to Windows Runtime Classes are Interfaces. When handling projected types of the Interfaces/Objects we are inherently holding a smart pointer. But how do we release a reference to the underlying object? It makes no sense to cast to the implementation, or to get IUknown somehow and calling release(). There's no function on the projected type to release. The winrt::final_release function seems to have been deprecated. There doesn't seem to be any other winrt function. ~IUknown does not sound like it would decrement the count. My only conclusion is to IInterface = nullptr. Great if that's the answer, and it might even work, but still be not the right answer.

Universal Windows Platform (UWP)
Windows App SDK
Windows App SDK
A set of Microsoft open-source libraries, frameworks, components, and tools to be used in apps to access Windows platform functionality on many versions of Windows. Previously known as Project Reunion.
750 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Iesha Jones 1 Reputation point

    Search it in windows

    0 comments No comments

  2. Rebeka Fox 106 Reputation points

    I was unaware that because I was implementing through a Proxy-Stub Server, that I was hiding the ->AddRef() and ->Release() functions. I assumed projection types hid this by default, which was an incorrect assumption. I had never implemented the expected way, or without 'late binding'. That said, projection type Midl 3.0 Interfaces are very much so smart pointers and when any reference goes out of scope the underlying object is decremented or assigning to another reference increments it. A simple test through the Proxy-Stub Server showed that setting any reference to nullptr decrements the internal objects count. ->Release() is not required. I love C++/WinRT and WinUI 3.0, these are amazing technologies.