FIX: ActiveControl Property of Screen Object Loses Memory

Last reviewed: October 30, 1997
Article ID: Q113031
3.00 WINDOWS kbprg kbbuglist

The information in this article applies to:

- Standard and Professional Editions of Microsoft Visual Basic for

  Windows, version 3.0

SYMPTOMS

It is possible to receive an "Out of Memory" error when using the ActiveControl property of the Visual Basic Screen object.

CAUSE

The ActiveControl property of the screen object can leak memory when used with the Is operator.

RESOLUTION

Use a temporary variable to work around the problem. For example, change the command click event in the code listed in the More Information section below to this code:

Sub Command1_Click ()
   Dim ctr As Long
   Dim ActControl As control
   Do
      ctr = ctr + 1
      Text1.Text = ctr
      ' Use a temporary object variable
      Set ActControl = Screen.ActiveControl
      If ActControl Is Command1 Then
      End If
   Loop
End Sub

This code should run indefinitely.

STATUS

Microsoft has confirmed this to be a bug in Visual Basic version 3.0 for Windows. This problem has been corrected in Visual Basic version 4.0.

MORE INFORMATION

Steps to Reproduce Problem

  1. Start a new project in Visual Basic. Form1 is created by default.

  2. Put a command button (Command1) and a text box (Text1) on the form.

  3. Add the following code to the command button's click event:

       Sub Command1_Click ()
          Dim ctr As Long
          Do
             ctr = ctr + 1
             Text1.Text = ctr
             If Screen.ActiveControl Is Command1 Then
             End If
          Loop
       End Sub
    
    

  4. Run the program, and you will receive an "Out of Memory" error eventually.


Additional reference words: buglist3.00 3.00 MemLeak fixlist4.00
KBCategory: kbprg kbbuglist
KBSubcategory: PrgOptMemMgt
Keywords : PrgOptMemMgt kbbuglist kbprg
Version : 3.00
Platform : WINDOWS
Solution Type : kbfix


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: October 30, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.