Handle leak (ALPC port) when using CreateObject() to create reference to a COM object

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
<p style="margin:0.5em 0em 0em; font-family:Arial,sans-serif; line-height:normal
<br/>

<p style="margin:0.5em 0em 0em; font-family:Arial,sans-serif; line-height:normal
Hi there,
<p style="margin:0.5em 0em 0em; font-family:Arial,sans-serif; line-height:normal
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.
<p style="margin:0.5em 0em 0em; font-family:Arial,sans-serif; line-height:normal

<p style="margin:0.5em 0em 0em; font-family:Arial,sans-serif; line-height:normal
Here is a sample of my testing code:
<p style="margin:0.5em 0em 0.0001pt; font-family:Arial,sans-serif; line-height:normal
<span style="font-family:Consolas
<pre class="prettyprint lang-vb" style=" Dim testExcel As Object Dim testWord As Object Private Sub Form_Load() <span class="x_Apple-tab-span" style="white-space:pre Set testExcel = CreateObject("Excel.Application") <span class="x_Apple-tab-span" style="white-space:pre Set testWord = CreateObject("Word.Application") End Sub Private Sub Form_Unload(Cancel As Integer) <span class="x_Apple-tab-span" style="white-space:pre If Not testExcel Is Nothing Then testExcel.Quit <span class="x_Apple-tab-span" style="white-space:pre Set testExcel = Nothing <span class="x_Apple-tab-span" style="white-space:pre If Not testWord Is Nothing Then testWord.Quit <span class="x_Apple-tab-span" style="white-space:pre Set testWord = Nothing End Sub [/code]
<p style="margin:0.5em 0em 0.0001pt; font-family:Arial,sans-serif; line-height:normal
<span style="font-family:Consolas <span style="font-family:Consolas
<p style="margin:0.5em 0em 0.0001pt; font-family:Arial,sans-serif; line-height:normal
Note:

From the process explorer, You could observe the “ALPC port” persists in the memory if you put a breakpoint at the end of the Form_Unlod method.The problem seems to happen when the COM object is complied as executable, DLL is fine.I tried both early binding and late binding, but it didn’t help to solve the problem.
<p style="margin:0.5em 0em 0.0001pt; font-family:Arial,sans-serif; line-height:normal
Thank you for your help!
<p style="margin:0.5em 0em 0.0001pt; font-family:Arial,sans-serif; line-height:normal

<p style="margin:0.5em 0em 0.0001pt; font-family:Arial,sans-serif; line-height:normal
Simon
<br/>

View the full article
 
Back
Top