8

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.

4

2 に答える 2

20

WRLのソースコードが提供されています。include/winrt/ wrl/client.hを参照してください。埋め込まれたCOMポインター(ptr_メンバー)は、InternalRelease()関数によって解放されます。ポインタに適した候補を解放する方法として、次のいずれかを作成します。

  • デストラクタ。ComPtr<>を使用する理由
  • nullptrの割り当て
  • ReleaseAndGetAddressOf()を使用して、長い道のり
  • Reset()の呼び出し

したがって、nullptrを割り当てるか、Reset()を呼び出すのが適切です。選択してください。または、インターフェイスポインタを自分で管理したいだけの場合は、まったく使用しないでください。ComPtrを使用する必要はありません。

于 2012-11-16T14:49:43.653 に答える
4

null ポインターを割り当てることができます。

于 2012-11-16T14:27:38.027 に答える