Release ComPtr Manually

I am using ComPtr (Microsoft :: WRL) to manage some DirectX11 resources. How can it be released manually?

The method "ReleaseAndGetAddressOf", if I understand correctly, only frees the pointer, 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 getting the raw pointer from "ReleaseAndGetAddressOf" calling "Release" on it, which I would like to avoid.

+7
source share
2 answers

The source code for the WRL is provided; look at include / winrt / wrl / client.h. The built-in COM pointer (ptr_ member) is freed by the InternalRelease () function. Create any of the following methods to free the index of suitable candidates:

  • destructor. Reason for using ComPtr <>
  • nullptr assignment
  • using ReleaseAndGetAddressOf (), long way
  • call to reset ()

Therefore, nullptr assignment or Reset () call are appropriate, take your choice. Or do not use it at all, if you just want to control the interface pointer yourself, of course, you do not need to use ComPtr.

+16
source

You can assign a null pointer.

+3
source

All Articles