Microsoft KB Archive/277765

= PRB: Reference to ActiveX EXE is not released when calling a function inside the GlobalMultiUse class in Visual Basic 6.0 =

Article ID: 277765

Article Last Modified on 8/24/2004

-

APPLIES TO


 * Microsoft Visual Basic 6.0 Enterprise Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition Service Pack 3
 * Microsoft Visual Basic 6.0 Enterprise Edition Service Pack 4

-



This article was previously published under Q277765





SYMPTOMS
The ActiveX EXE process in Microsoft Visual Basic does not quit when the calling client releases the reference to it.



CAUSE
This problem occurs because the Visual Basic ActiveX DLL that references the GlobalMultiUse class is complied when the Retained in Memory option is enabled.

A client program starts a Visual Basic ActiveX EXE process by instantiating a MultiUse class inside the ActiveX EXE. The ActiveX EXE process then makes a call to a Visual Basic ActiveX DLL that was compiled when the Retained in Memory option was enabled. If this ActiveX DLL then uses a GlobalMultiuse class from a separate Visual Basic ActiveX DLL, the ActiveX EXE process does not unload from memory when the original calling client releases the reference to the ActiveX EXE.



WORKAROUND
To work around this problem, use one of the following methods:
 * Move the functions that are used in the GlobalMultiUse class to a standard Visual Basic module instead.
 * Do not compile the Visual Basic ActiveX DLL that references the GlobalMultiUse class when the Retained in Memory option is enabled.



STATUS
Microsoft is researching this problem and will post more information in this article when the information becomes available.



Steps to reproduce the behavior
 Create a new Visual Basic ActiveX EXE project with one MultiUse class.  Paste the following code in the MultiUse class: Public Function go As Long 'Call a method inside an in-process Visual Basic ActiveX DLL 'Multi-Use class Set oObject = CreateObject(&quot;RIMDLL.clsRIMDLL&quot;) i = oObject.DoSomeWork Set oObject = Nothing End Function  On the Project menu, click Properties. Type ActiveXTester in the Project Name box, and then click to select Unattended Execution.</li> On the File menu, click Make ActiveXTester.exe to compile the project in an ActiveX EXE.</li> In a separate instance of Visual Basic, create an ActiveX DLL project.</li> On the Project menu, click Properties.</li> Type GMUDLL in the Project Name box.</li>  Change the instancing property of the default class to GlobalMultiUse, and then paste the following function into that class: Public Function PublicFunction As Long PublicFunction = 0 End Function </li> On the File menu, click Make GMUDLL.DLL to compile the project in an ActiveX DLL.</li> Start a third instance of Visual Basic, and then create an ActiveX DLL project.</li> On the Project menu, click Properties.</li> Type RIMDLL in the Project Name box, and then click to select the Retained in Memory and Unattended Execution check boxes.</li> On the Project menu, click References, and then add a reference to the GMUDLL.DLL.</li> Click Make GMUDLL.DLL on the File menu to compile the project in an ActiveX DLL.</li>  Paste the following code into the default class: Public Function DoSomeWork As Long l = PublicFunction End Function </li> Change the name of the default class to clsRIMDLL.</li> To compile this project in a DLL, click Make RIMDLL.DLL on the File menu.</li>  Test the ActiveX EXE by running the following VBScript code: Set oActiveXEXE = CreateObject(&quot;ActiveXTester.Class1&quot;) lRet = oActiveXEXE.go Set oActiveXEXE = nothing </li></ol>

You expect that the ActiveX EXE process will be unloaded from memory when the script is completed. However, it remains. If the RIMDLL.DLL is recompiled when the Retained in Memory option is not enabled, the problem does not occur.

Additional query words: ref count

Keywords: kbprb KB277765

-

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

© Microsoft Corporation. All rights reserved.