Microsoft KB Archive/308644

= BUG: Memory Leak When You Bind a Recordset to Visual Basic Intrinsic Controls =

Article ID: 308644

Article Last Modified on 10/21/2005

-

APPLIES TO


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

-



This article was previously published under Q308644



SYMPTOMS
If your Visual Basic application includes Visual Basic intrinsic controls (such as TextBox controls) on the form, when the code repeatedly binds a Recordset object to the control with the DataSource property of the control, you may notice that memory usage grows while the application runs.



CAUSE
This problem occurs because the Recordset object is not released even if you set DataSource to Nothing.



RESOLUTION
A supported hotfix is now available from Microsoft, but it is only intended to correct the problem that this article describes. Apply it only to systems that are experiencing this specific problem.

Note You must have a Visual Studio license agreement to obtain this hotfix.

To resolve this problem, contact Microsoft Product Support Services to obtain the hotfix. For a complete list of Microsoft Product Support Services telephone numbers and information about support costs, visit the following Microsoft Web site:

http://support.microsoft.com/contactus/?ws=support

Note In special cases, charges that are ordinarily incurred for support calls may be canceled if a Microsoft Support Professional determines that a specific update will resolve your problem. The usual support costs will apply to additional support questions and issues that do not qualify for the specific update in question. The English version of this fix should have the following file attributes or later:   Date        Time  Version      Size     File name 25-Sep-2001 8:03 6.0.93.63    1.33 MB  MSVBVM60.dll 25-Sep-2001 8:03 6.0.93.63    1.79 MB  VB6.exe



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.



Steps to Reproduce Behavior
 Create a new Standard EXE application in Visual Basic. Form1 is created by default. On the Project menu, click References. Select the Microsoft ActiveX Data Objects 2.x Library check box, and then click OK. Place a TextBox control and a CommandButton control on Form1. Keep the default names for these two controls.  Add the following code to the code window of Form1: Option Explicit

Private mRecordset As ADODB.Recordset

Private Sub ClearDataSource Text1.DataField = vbNullString Set Text1.DataSource = Nothing Set mRecordset = Nothing End Sub

Private Sub Command1_Click

Dim lOffset As Integer For lOffset = 1 To 100 Step 1 ClearDataSource CreateADO Text1.DataField = &quot;firstname&quot; Set Text1.DataSource = mRecordset Next lOffset End Sub

Private Sub CreateADO Set mRecordset = New Recordset mRecordset.CursorLocation = adUseClient mRecordset.LockType = adLockBatchOptimistic Set mRecordset.ActiveConnection = Nothing

mRecordset.Fields.Append &quot;firstname&quot;, adVarChar, 10 mRecordset.Open mRecordset.AddNew mRecordset(0) = &quot;Joe&quot; mRecordset.MoveFirst End Sub  Build and run the application.</li> Click the command button repeatedly. Use Performance Monitor or Task Manager to monitor the memory usage.</li></ol>

Keywords: kbbug kbqfe kbpending KB308644

-

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

© Microsoft Corporation. All rights reserved.