INFO: Leaking Handles When Creating COM ObjectsID: Q237757
|
When a Visual Basic application creates COM objects that are instantiated in an out-of-process server, observe the number of handles shown in the performance tab of the NT task manager. You might see the number of handles increasing, without returning to its initial level when the objects are released.
Although this behavior appears to be a leak, it is not. This behavior is by design.
Visual Basic does not release the handles it creates immediately after it uses them; it caches them. When the number of handles reaches a given level, they are released and new allocations start again when they are needed. All handles are recovered when the client application is closed.
This is the expected behavior. Visual Basic is just optimizing the creation/release of handles internally.
You can observe this behavior by doing the following under Windows NT:
Public Function GetLong()
GetLong=1
End Function
Private Sub Command1_Click()
Dim i As Long
Dim MyObj As MyServer.Class1
Label1.Caption = "Creating..."
Form1.Refresh
For i = 1 To 200
Set MyObj = CreateObject("MyServer.Class1")
Set MyObj = Nothing
Next i
Label1.Caption = "Done"
End Sub
Additional query words:
Keywords : kbActiveX kbCOMt kbVBp600 kbGrpVB kbDSupport
Version : WINDOWS:6.0
Platform : WINDOWS
Issue type : kbinfo
Last Reviewed: August 12, 1999