Microsoft KB Archive/315922

= MSScript.ocx Leaks Event Handles in Applications That Repeatedly Create and Destroy Threads =

Article ID: 315922

Article Last Modified on 6/10/2002

-

APPLIES TO


 * Microsoft Visual Basic 5.0 Enterprise Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition
 * Microsoft Visual Basic 5.0 Professional Edition
 * Microsoft Visual Basic 6.0 Professional Edition

-



This article was previously published under Q315922



SYMPTOMS
When you use the Microsoft Script control (MSScript.ocx) in an environment that repeatedly creates and destroys threads, MSScript.ocx leaks event handles. For each thread that is created and destroyed, an event handle is leaked if one or more objects of the Script control are created on that thread.



WORKAROUND
Do not repeatedly create and destroy threads; use a thread pool instead.



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article. Microsoft is researching this problem and will post more information in this article when the information becomes available.



Steps to Reproduce Behavior
 In Visual Basic, create an ActiveX EXE project named Repro. A default class named Class1 is created by default. Add a form to the project. Keep the default name Form1. Add Microsoft Script Control 1.0 to the toolbox, and then add an instance of the control to Form1.  Add the following code to Class1: Dim f As New Form1 Private Sub Class_Initialize f.Visible = True End Sub Private Sub Class_Terminate Unload f End Sub  Change the threading model of the project to Thread per Object, and then build the project. In Visual Basic, create a Standard EXE project. Keep the default name Project1. Form1 is created by default.</li>  Add a command button to Form1, and then add the following code to Form1: Dim server As Object Private Sub Command1_Click Dim o As Object Set o = CreateObject(&quot;repro.class1&quot;) Set o = Nothing End Sub

Private Sub Form_Load Set server = CreateObject(&quot;repro.class1&quot;) End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer) Set server = Nothing End Sub </li> Build and run Project1. Notice that two processes, Project1.exe and Repro.exe, are started.</li> Use Performance Monitor or Task Manager to monitor the handle count for Repro.exe.</li> Repeatedly click the command button on Form1 of Project1, and then observe the handle count for the Repro.exe process. Notice that each time you click the button, an instance of the control is created and destroyed, and the handle count for Repro.exe increases by 1.</li></ol>

Additional query words: msscript

Keywords: kbbug kbpending KB315922

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.