在具有_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.
更多推荐
发布评论