Mark
Mark

Reputation: 2112

is ->Release() called on the destructor of COM objects?

If I have the following:

ID3D11Buffer **buffers;    //ID3D11Buffer is a com object
buffers=new ID3D11Buffer* [num];

Then if I do this:

delete[] buffers;
Will the Release() method of each ID3D11Buffer* be called automatically, or do I have to call them myself?

Upvotes: 2

Views: 2410

Answers (2)

Mark Ransom
Mark Ransom

Reputation: 308206

Calling delete on an array will destroy each element of the array. But since each element is a POD dumb pointer, destructing it doesn't do anything. If you want the COM objects to be released automatically, you should use a smart pointer such as _com_ptr_t or CComPtr.

Upvotes: 9

Adam Maras
Adam Maras

Reputation: 26853

All delete[] buffers; will do is free the array containing the pointers to the COM objects. You do need to loop through the array and Release() each of them by hand.

Upvotes: 8

Related Questions