FIX: ADO 2.5 Leaks Resources When Using Stream and Record Objects

Article translations Article translations
Article ID: 282177 - View products that this article applies to.
This article was previously published under Q282177
This article has been archived. It is offered "as is" and will no longer be updated.
Expand all | Collapse all

On This Page

SYMPTOMS

When marshalling data in-process using ActiveX Data Objects (ADO) Record or Stream objects, a memory leak may occur that can eventually cause the process to run out of memory. This leak does not occur with other ADO objects such as Command and Recordset objects.

This leak occurs in Microsoft Data Access Components (MDAC) 2.5 but does not occur in MDAC 2.6.

CAUSE

The Record and Stream objects use the Active Template Library (ATL) AtlMarshalPtrInProc function to create a stream that is used to send proxy information back to the caller. When the Record and Stream objects are destroyed, the Release function is simply called on the stream, without first calling the AtlFreeMarshalStream function to free the memory allocated for this stream.

RESOLUTION

MDAC

To resolve this problem, obtain the latest service pack for Microsoft MDAC 2.5. For additional information, click the following article number to view the article in the Microsoft Knowledge Base:
293312INFO: How to Obtain the Latest MDAC 2.5 Service Pack
The English version of this fix should have the following file attributes or later:
   Date          Version        Size               File name
   ------------------------------------------------------------

   12/14/2000    2.53.6013.0    491,792 bytes      Msado15.dll	
	
				

Windows 2000

To resolve this problem, obtain the latest service pack for Windows 2000. For additional information, click the following article number to view the article in the Microsoft Knowledge Base:
260910 How to Obtain the Latest Windows 2000 Service Pack
The English version of this fix should have the following file attributes or later:
   Date        Time    Version       Size       File name
   ----------------------------------------------------------
   5/29/2001   02:56p  2.52.6019.1   487,696    Msado15.dll
				

WORKAROUND

There is no workaround for this problem with MDAC 2.5.

STATUS

MDAC

Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article. This problem was first corrected in Microsoft MDAC 2.5 Service Pack 3.

This problem does not occur in MDAC 2.6.

Windows 2000

Microsoft has confirmed that this is a problem in the Microsoft products that are listed at the beginning of this article. This problem was first corrected in Windows 2000 Service Pack 3.

MORE INFORMATION

This memory leak occurs predominantly in environments where the Record or Stream objects are marshalled in-process, such as Microsoft Internet Information Server (IIS) and Microsoft Transaction Server (MTS)/COM+. This leak does not occur in environments where this marshalling does not occur, such as a standalone Microsoft Visual Basic application.

Steps to Reproduce Behavior

  1. Paste the sample code below into a text file and save it with the name "ADODBMem.vbs".
  2. From the command prompt, run this file by using the Windows Scripting Host (CScript.exe). For example:
    cscript ADODBMem.vbs
  3. When prompted, start Performance Monitor (PerfMon), and select the Private Bytes counter for the CScript executable.
  4. Return to the script, and step through the creation of the ADO objects as indicated. Note that PerfMon shows an increasing amount of memory allocated with Record and Stream objects.

Sample Code

'//////////////////////////////////////////////////////////////////////////////////////////////// 
' +
'   File:       adodbmem.vbs
'
'   Copyright:  (c) 2000 Microsoft Corporation
'
'   Contents:   Creates/destroys ADODB objects and allows to see memory usage (leaks).
'
'   Comments:   CScript.exe v2.0 required (comes with Windows 2000; just copy to run under NT4)
'               WScript.exe will NOT work
'
'               Usage: cscript adodbmem.vbs
'               Use PerfMon to see the counter "Private Bytes" in process "cscript"
' -
'//////////////////////////////////////////////////////////////////////////////////////////////// 

Const REPT_CNT = 1000

Private Function CreateOnce(objName, bStop)
  Dim obj
  On Error Resume Next
  If bStop = True Then
    WScript.StdOut.Write  "Create an instance of " & objName & ">"
    WScript.StdIn.ReadLine
  End If
  Set obj = CreateObject(objName)
  If Err.Number <> 0 Then
    WScript.Echo "CreateObject(" & objName &") failed: " & Err.Description
    CreateOnce = False
    Exit Function
  End If
  If bStop = True Then
    WScript.StdOut.Write objName & " created. Destroy>"
    WScript.StdIn.ReadLine
  End If
  Set obj = Nothing
  If bStop = True Then
    WScript.Echo objName & " destroyed."
  End If
  CreateOnce = True
End Function

'//////////////////////////////////////////////////////////////////////////////////////////////// 

Private Sub TryObject(objName)
  Dim i
  WScript.StdOut.Write "Create and destroy " & objName & " " & REPT_CNT & " times>"
  WScript.StdIn.ReadLine
  For i = 1 To REPT_CNT
    If Not CreateOnce(objName, False) Then Exit For
  Next
  WScript.StdOut.Write "Done. "
End Sub

'//////////////////////////////////////////////////////////////////////////////////////////////// 

Private Sub ShowVersion
  Dim sVer
  Dim o
  Set o = CreateObject("ADODB.Connection")
  sVer = o.Version
  Set o = Nothing
  WScript.StdOut.Write "ADODB version " & sVer & " loaded. Hit Enter to start>"
  WScript.StdIn.ReadLine
End Sub

'//////////////////////////////////////////////////////////////////////////////////////////////// 

Public sub Main()
  WScript.StdOut.Write "ADODB memory leak test." & vbNewLine & _
                "Connect Perfmon: process - cscript, counters - Private Bytes." & vbNewLine & _
                "Hit Enter then ready>"
  WScript.StdIn.ReadLine
  ShowVersion

  TryObject "ADODB.Command"
  TryObject "ADODB.Stream"
  TryObject "ADODB.Recordset"
  TryObject "ADODB.Record"

  WScript.StdOut.Write "All Done. Hit Enter to exit>"
  WScript.StdIn.ReadLine
End sub

Call Main()
Wscript.Quit 0

'//////////////////////////////////////////////////////////////////////////////////////////////// 
'                                  End of file "adodbmem.vbs"
'//////////////////////////////////////////////////////////////////////////////////////////////// 

				

Properties

Article ID: 282177 - Last Review: February 28, 2014 - Revision: 3.2
APPLIES TO
  • Microsoft Data Access Components 2.5 Service Pack 1
  • Microsoft Data Access Components 2.5
Keywords: 
kbnosurvey kbarchive kbhotfixserver kbqfe kbmdac250sp3fix kbado260fix kbbug kbfix kbmdac260fix kbwin2000sp3fix KB282177

Give Feedback

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com