使用CreateObject()创建对COM对象的引用时处理泄漏(ALPC端口) [英] Handle leak (ALPC port) when using CreateObject() to create reference to a COM object

查看:206
本文介绍了使用CreateObject()创建对COM对象的引用时处理泄漏(ALPC端口)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述






你好,


我支持传统的VB6系统。我最近发现因使用  CreateObject() 创建  并返回对COM对象的引用而导致出现句柄泄漏。此句柄泄漏类型在Process Explorer中显示为"ALPC   port"
。我曾尝试从我的引用中退出COM对象,并在我的代码中将引用设置为Nothing,但是这个句柄没有被销毁。虽然这个句柄看起来超时并最终退出,但我想知道你是否有任何
你有更好的分辨率。如果您有这方面的经验,或者知道这个问题的原因和解决方法,请在此处发布。  我的操作系统是Windows Server 2008 R1和Windows 7 SP1。

I am supporting a legacy VB6 system. I recently discover a handle leak appears caused by using the CreateObject() to create  and return a reference to a COM object. This handle leak type is shown as "ALPC  port" at the Process Explorer. I had tried to exit the COM object from my reference and set the reference to Nothing at my code, but this handle did not got destroyed . Although this handle looks timeout and eventually exit itself, I would like to know if anyone of you have better resolution. Please post here if you have experience of this, or knowing what is the cause and fix of this problem.   My OS are windows server 2008 R1 and Windows 7 SP1.



这是我的一个示例测试代码:

Here is a sample of my testing code:


Dim testExcel As Object

Dim testWord As Object  

Dim testWord As Object  

Private Sub Form_Load()    

Private Sub Form_Load()    

设置testExcel = CreateObject(" Excel.Application")    

Set testExcel = CreateObject("Excel.Application")    

设置testWord = CreateObject(" Word.Application")

Set testWord = CreateObject("Word.Application")

End Sub 

End Sub 

Private Sub Form_Unload(取消作为整数)    

Private Sub Form_Unload(Cancel As Integer)    

如果不是testExcel,那么testExcel.Quit    

If Not testExcel Is Nothing Then testExcel.Quit    

设置testExcel = Nothing       

Set testExcel = Nothing       

如果不是testWord,那么testWord.Quit    

If Not testWord Is Nothing Then testWord.Quit    

设置testWord = Nothing

Set testWord = Nothing

End Sub



   


注意:


  • 从流程资源管理器中,您可以观察到"ALPC   port"内存,如果你在Form_Unlod方法的末尾放置一个断点。
  • 当COM对象被编译为可执行文件时,似乎会发生问题,DLL很好。
  • 我早就试过了绑定和后期绑定,但它没有帮助解决问题。


感谢您的帮助!

Thank you for your help!



Simon

Simon

推荐答案

进程外ActiveX组件在满足以下所有条件时正确卸载

An out of process ActiveX component is correctly unloaded when all of the following coditions are met

答:客户端应用程序中指向对象的变量服务器已明确或隐式设置为空,因为它们超出了范围

A : The variables in a client app that point to objects in the server have been set to nothing explicitly or implicitly because they went out of scope

B:没有请求在服务器对象等待服务的队列中

B: No Request is in the queu for the server object waiting to be served

C:服务器当前没有加载任何形式(可变或不可见)

C: The server has no form currently loaded ( vissible or invissible )

D:服务器没有执行匿名代码

D: The server isn`t executing anny code

注意如果您在excel等中使用了工作簿,则需要先将其关闭

Note  if you used a workbook  in excel etc etc you need to close it first

VB6中的另一个常见错误是人们在表单终止从代码中引用表单或其控件之一的事件在这种情况下,Visual Basic不会引发错误,但它会默默地创建该表单的新实例,默认情况下,
仍然存在隐藏在记忆中  。

Another common mistake in VB6 is that people write code in the forms terminate event that refernce the form or one of its controls from code  in that case Visual basic doesn`t raise an error but it silently creates a new instance of that form wich silently remains hidden in memory  .

HTH

Michel Posseth  

Michel Posseth   

 


这篇关于使用CreateObject()创建对COM对象的引用时处理泄漏(ALPC端口)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆