在重新分配CreateInstance之前需要释放com

编程入门 行业动态 更新时间:2024-10-21 22:59:33
在重新分配CreateInstance之前需要释放com_ptr_t吗?(Need to Release a com_ptr_t before reassigning with CreateInstance?)

在具有_com_ptr_t成员的C ++类中,如果在同一指针上重复使用CreateInstance()以获取COM对象的新实例,而不首先执行Release(),则内存是否会泄漏? 有充分证据表明,当其中一个智能指针超出范围时,ref计数会减少,而当封装指针是Detach()时,则不会减少。 MSDN似乎没有提到重复CreateInstance()时引用计数的含义。

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 implications of ref counting when repeating CreateInstance().

最满意答案

由于_com_ptr_t在CreateInstance()的开头调用Release() CreateInstance() ,您可以通过阅读_com_ptr_t实现轻松验证自己,因此不会发生泄漏。

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.

更多推荐

本文发布于:2023-08-04 04:32:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1409387.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:分配   CreateInstance

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!