I’m using ComPtr (Microsoft::WRL) to manage some DirectX11 resources.
How can I manually release it?
The “ReleaseAndGetAddressOf” method if I understand correctly, only frees the pointer and not the resource itself (which is returned), and I’m not sure about the “Reset” method.
The only alternatives I could think of are manually calling the pointer destructor, or after obtaining the raw pointer from “ReleaseAndGetAddressOf” calling “Release” on that, which I would like to avoid.
The source code for WRL is provided, have a look at include/winrt/wrl/client.h. The embedded COM pointer (ptr_ member) is released by the InternalRelease() function. Making any of the following a way to release the pointer suitable candidates:
So assigning nullptr or calling Reset() are a good fit, take your pick. Or don’t use it at all if you just want to manage the interface pointer yourself, it certainly isn’t required to use ComPtr.