VB6 ADO 2.6 SP2 memory probs

From: Steve P (anonymous_at_discussions.microsoft.com)
Date: 02/25/04


Date: Wed, 25 Feb 2004 06:11:08 -0800

Hi,

Our application uses a COM object to store data on the client, within the object there are several layers of collections, as a general rule each top level member in the collection contains about 100 members of the lowest level. Each member of the lowest level exposes data as properties, one of which is an ado recordset. This works fine with small top level collections. We have a problem with memory leaks when the user creates an object a lot (100+) top level members...

I tested creating and destroying this number of recordsets (100 * 100 = 10000) in a similar way to how the object does, and I suspect this is causing the problem.

Test project loads the rs's into an array, adds a dummy record, then destroys them when the form is closed. Most of the memory in task manager is not reclaimed until VB is closed.

Please see following test code, I am missing something obvious, or is there a max limit to recordsets we can use??

Option Explicit
Dim objRS() As ADODB.Recordset

Private Sub Form_Load()
Dim lng As Long

    Do Until lng = 10000
        ReDim Preserve objRS(lng)
        Set objRS(lng) = CreateRS
        With objRS(lng)
            .AddNew
            .Fields("A_Field").Value = 1
            .Update
        End With
        lng = lng + 1
    Loop
    
Debug.Print Now
End Sub
Private Function CreateRS() As ADODB.Recordset
Dim TempRS As ADODB.Recordset

    Set TempRS = New ADODB.Recordset
    TempRS.CursorLocation = adUseClient
    TempRS.Fields.Append "A_Field", adInteger, 4
    TempRS.Open
    Set CreateRS = TempRS
    Set TempRS = Nothing

End Function

Private Sub Form_Unload(Cancel As Integer)
Dim lng As Long

    Do Until lng = UBound(objRS())
        Set objRS(lng) = Nothing
        lng = lng + 1
    Loop
    Erase objRS()

End Sub

TIA, Steve