Microsoft KB Archive/282177

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

Article ID: 282177

Article Last Modified on 9/26/2005

-

APPLIES TO


 * Microsoft Data Access Components 2.5 Service Pack 1
 * Microsoft Data Access Components 2.5

-



This article was previously published under Q282177



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.



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.



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
 Paste the sample code below into a text file and save it with the name &quot;ADODBMem.vbs&quot;. From the command prompt, run this file by using the Windows Scripting Host (CScript.exe). For example:

cscript ADODBMem.vbs

 When prompted, start Performance Monitor (PerfMon), and select the Private Bytes counter for the CScript executable. 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.</li></ol>

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 &quot;Private Bytes&quot; in process &quot;cscript&quot; ' - '////////////////////////////////////////////////////////////////////////////////////////////////

Const REPT_CNT = 1000

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

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

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

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

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

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

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

TryObject &quot;ADODB.Command&quot; TryObject &quot;ADODB.Stream&quot; TryObject &quot;ADODB.Recordset&quot; TryObject &quot;ADODB.Record&quot;

WScript.StdOut.Write &quot;All Done. Hit Enter to exit>&quot; WScript.StdIn.ReadLine End sub

Call Main Wscript.Quit 0

'//////////////////////////////////////////////////////////////////////////////////////////////// '                                 End of file &quot;adodbmem.vbs&quot; '////////////////////////////////////////////////////////////////////////////////////////////////

Additional query words: kbMDAC marshal marshaling marshaled

Keywords: kbbug kbfix kbado260fix kbqfe kbwin2000sp3fix kbmdac260fix kbmdac250sp3fix kbhotfixserver KB282177

-

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

© Microsoft Corporation. All rights reserved.