Microsoft KB Archive/190067

= BUG: Object References Might Not Be Released Properly =

Article ID: 190067

Article Last Modified on 5/12/2003

-

APPLIES TO


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

-



This article was previously published under Q190067



SYMPTOMS
If a function call to an object returns a Variant and the Variant is not assigned to a local variable, Visual Basic might not dereference the object correctly. As a result, a new thread is created in the object's process space each time the function is called.



RESOLUTION
Assign the function's return value to a local variable, regardless of whether or not it is needed.

Example
The class clsMyObject has a function called MyVariantFunction that returns a Variant:

Public Function MyVariantFunction As Variant

If the return result of the function is not needed, calling the function without assigning the return value might cause new threads to be created:

Public Sub TestFunction clsMyObject.MyVariantFunction End Sub

To avoid the unnecessary creation of threads, assign the function's return value to a local variable, regardless of whether or not it is needed:

Public Sub TestFunction Dim vReturnValue As Variant

' Although this will not be used, it guarantees proper dereferencing. vReturnValue = clsMyObject.MyVariantFunction End Sub



STATUS
Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. We are researching this bug and will post new information here in the Microsoft Knowledge Base as it becomes available.



MORE INFORMATION
This type of behavior usually occurs when returning variant arrays that contain user-defined types.

Keywords: kbbug kbpending KB190067

-

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

© Microsoft Corporation. All rights reserved.