开发者

Need to Release a com_ptr_t before reassigning with CreateInstance?

开发者 https://www.devze.com 2023-04-02 05:27 出处:网络
In a C++ class with _com_ptr_t members, will memory leak if CreateInstance() is repeatedly used on the same pointer to get fresh instances of COM objects, without first performing a Release()?It\'s we

In a C++ class with _com_ptr_t members, will memory leak if CreateInstance() is repeatedly used on the same pointer to get fresh instances of COM objects, without first performing a Release()? It's well documented that ref count is decremented when one of these smart pointers goes out of scope, and that it is not when the encapsulated pointer is Detach()ed. MSDN doesn't seem to mention the imp开发者_开发百科lications of ref counting when repeating CreateInstance().


No leak will occur since _com_ptr_t calls Release() at the beginning of CreateInstance() which you can easily verify yourself by reading _com_ptr_t implementation.


CreateInstance() calls _Release() before calling the CoCreateInstance(). Please see the implementation inside.

0

精彩评论

暂无评论...
验证码 换一张
取 消