Releasing WinRT Runtime Classes

Rebeka Fox 106 Reputation points
2022-08-25T08:46:08.287+00:00

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.
725 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Iesha Jones 1 Reputation point
    2022-08-25T14:45:39.17+00:00

    Search it in windows

    0 comments No comments

  2. Rebeka Fox 106 Reputation points
    2022-08-26T09:44:19.507+00:00

    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.