ATL COM 对象的析构函数代码应该放在哪里?
我在 ATL COM 对象中定义的内容的析构函数代码属于哪里?
它应该放在 ~MyComClass()
中还是 MyComClass::FinalRelease()
中?
Where does the destructor code for things I have defined in an ATL COM object belong?
Should it go in ~MyComClass()
or in MyComClass::FinalRelease()
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只要
FinalRelease
存在问题,我就假设您的问题与 ATL 相关。在大多数情况下,您可以使用两者中的任何一个来清理内容。
FinalRelease
将在实际析构函数之前立即调用。重要的区别是,如果您聚合其他对象,FinalRelease 使您有机会在顶级 COM 对象类(尤其是CComObject
)的实际析构函数开始工作之前清理引用并释放依赖项。也就是说,您可以分两步清理内容,首先引用
FinalRelease
中的聚合对象,然后引用FinalRelease
或析构函数中的其他内容。As long as
FinalRelease
is in question, I assume your question is related to ATL.In most cases you can clean things up in either of the two.
FinalRelease
will be called immediately before the actual destructor. The important difference is that if you aggregate other objects, FinalRelease gives you a chance to clean the references and release dependencies before actual destructor of top level COM object class (esp.CComObject
) starts working.That is, you clean things up in two steps, first references to aggregated objects in
FinalRelease
and then other things in eitherFinalRelease
or destructor.这是一般方法:
编辑:
FinalRelease()
似乎与我不熟悉的 ATL 相关。This is the general approach:
EDIT:
FinalRelease()
appears to be related to ATL which I am unfamiliar with.