尽管我使用 Marshal.FinalReleaseComObject,但不取消订阅 COMObject 事件会导致内存泄漏吗?
尽管我使用 Marshal.FinalReleaseComObject,但不取消订阅 COMObject 事件会导致内存泄漏吗?
我在我的类中定义了新成员 COMObject
protected COMObject.Call call_ = null;
该类具有我订阅的以下事件处理程序
call_.ActionA += new COMObject.AEventHandler(AEvent);
call_.ActionB += new COMObject.BEventHandler(BEvent);
call_.Destructed += new COMObject.DestructedEventHandler(CallDestructedEvent);
当调用 Destructed 事件时,我执行 Marshal.FinalReleaseComObject
Marshal.FinalReleaseComObject(call_)
但不取消订阅事件
call_.ActionA -= new COMObject.AEventHandler(AEvent);
call_.ActionB -= new COMObject.BEventHandler(BEvent);
call_.Destructed -= new COMObject.DestructedEventHandler(CallDestructedEvent);
这是否会导致内存泄漏?或者GC会处理它? 你能将你的答案链接到一些 MSDN 或文章吗?
谢谢!多尔。
Do not unsubscribe from COMObject events can cause memory leak although I use Marshal.FinalReleaseComObject?
I have defined new member in my class that is COMObject
protected COMObject.Call call_ = null;
This class has the following event handlers that I subscribed to
call_.ActionA += new COMObject.AEventHandler(AEvent);
call_.ActionB += new COMObject.BEventHandler(BEvent);
call_.Destructed += new COMObject.DestructedEventHandler(CallDestructedEvent);
When the Destructed event is called I do Marshal.FinalReleaseComObject
Marshal.FinalReleaseComObject(call_)
but not unsubscribe from the events
call_.ActionA -= new COMObject.AEventHandler(AEvent);
call_.ActionB -= new COMObject.BEventHandler(BEvent);
call_.Destructed -= new COMObject.DestructedEventHandler(CallDestructedEvent);
Is this can cause memory leak? or that the GC will handle it?
Can you link your answer to some MSDN or article?
Thanks! Dor.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否在发布之前尝试取消订阅它们,看看是否有助于内存泄漏?
你有一个被破坏的处理程序,你可以在那里做。
您是否曾经调用过 COM 对象的任何属性?如果您这样做了,您是否已释放他们也正确吗?
我认为即使您在父对象上调用 FinalReleaseComObject,如果您也没有释放子对象,那么即使没有对父对象的引用,仍然可能有对挂起的子对象的引用。
Have you tried unsubscribing them before doing the release to see if it helps the memory leak?
You've got a destructed handler, you could do it in there.
Do you ever call any of the properties of the COM object, and if you do, have you released them properly too?
I think that even if you call FinalReleaseComObject on the parent object, if you haven't released the child objects too then even though there are no reference to the parent there may still be references to the children hanging about.