handle count keeps going up

K

Keith Langer

I have a reference to the MSXML4 library via COM (I need to use this
library for legacy XSLT), and my handle count goes up by 4 each time
an object is created and destroyed.

Here is a simple example that will create the problem (you must add a
reference to MSXML4, or MSXML3 with DOMDocument40 changed to
DOMDocument30)

Sub Main()
Do While True
Dim X As New MSXML2.DOMDocument40
X = Nothing
System.Threading.Thread.Sleep(1000)
Loop
End Sub

Any idea what's going on here? I'm guessing that there is some sort
of "lazy garbage disposal" that may happen at some point, but I'd
prefer not to wait that long.

thanks,
Keith
 
K

Klaus H. Probst

Well, you might try to call GC.Collect() and see if that does it. You will
take a performance hit, but how big depends on the situation these objects
are being used in and so on. No two memory usage scenarios are equal.

I wouldn't worry about it of you're running on 2K/XP, unless the handles are
*never* released and eventually cause a problem.
 
K

Keith Langer

Klaus,

Thanks for the suggestion. Running GC.Collect does the trick. I also
found that System.Runtime.InteropServices.Marshal.ReleaseComObject
releases the handles.

When I ran my program, the handle count got over 10,000. Is it possible
that the garbage collector isn't running because the reference is not to
a managed object?

Keith
 
K

Klaus H. Probst

Keith Langer said:
Thanks for the suggestion. Running GC.Collect does the trick. I also
found that System.Runtime.InteropServices.Marshal.ReleaseComObject
releases the handles.
Yep.

When I ran my program, the handle count got over 10,000. Is it possible
that the garbage collector isn't running because the reference is not to
a managed object?

No, the COM object is still wrapped in a managed object.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top