Microsoft KB Archive/73808

= PRB: Deleting VB Control Doesn't DeIete Its Code from Memory =

Article ID: 73808

Article Last Modified on 11/18/2003

-

APPLIES TO


 * Microsoft Visual Basic 1.0 Standard Edition
 * Microsoft Visual Basic 2.0 Standard Edition
 * Microsoft Visual Basic 3.0 Professional Edition

-



This article was previously published under Q73808



SYMPTOMS
When you delete a control in the Visual Basic environment, the code that you wrote for that control is not deleted, but is instead moved to the Object: (General) area for code.

Some programmers may not realize that these detached (unused) procedures still exist and consume memory. The detached code is available for calling, copying, or reuse. For example, when you add a control that shares the same name as a detached procedure, the detached event procedure reassociates with that control.



RESOLUTION
If you want to delete both the control and its associated code, you need to manually select and delete the code in each event procedure for that control in addition to deleting the control itself.



STATUS
This behavior is by design.



MORE INFORMATION
The following example demonstrates that your code goes into the Object: (General) area after you delete the associated control (or object):

 From the File menu, choose New Project. Double-click a command button from the Toolbox to put a Command1 button on your form. Double-click the Command1 button to bring up the code window for the Command1_Click event procedure.  Enter the following code inside the Command1_Click procedure: Sub Command1_Click Print &quot;Hello&quot; End Sub  Press the F5 key to run the code. Click the Command1 button to see the text &quot;Hello&quot; display on Form1 in the upper left corner. From the Run menu, choose End to stop the program. Click the Command1 button on Form1 to set the focus there and either press the DELETE key or choose the Delete command from the Edit menu. This deletes the Command1 button from the form.

At this point, some programmers may incorrectly assume that the code associated with the Command1 button was also deleted. Actually, the code associated with any deleted object is automatically moved into the Object: (general) area of the Code window for that form. You can find the detached procedures in the Code window by choosing (general) from the Object: box, and choosing the procedures from the Proc: box. (Click the DOWN arrow symbol on the right of the Object: and Proc: boxes to see your choices.)</li></ol>

Additional query words: 2.00 3.00

Keywords: kbprb KB73808

-

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

© Microsoft Corporation. All rights reserved.