Solved

Memory Leaks with ADO (with COM and C++)?  (HELP!!!!)

Posted on 2001-07-17
5
545 Views
Last Modified: 2013-12-03
Hi,

I was wondering if anyone can spot what I am doing wrong with the following code. It is using COM and ADO to communicate with a MySQL database.

However, when I close the recordset, I do not get all the allocated memory back (according to the task manager.) I ran the perfmon app, and it too reported very severe memory leaks. The private bytes of my process grew exponentially as the program continued to run.

When I ran the program in debug mode, an exception is called when the Open method of the inRecords variable (see code, above). The debug window reports the following messages:

  HEAP[DataAgent.exe]: Invalid Address specified to RtlFreeHeap( 130000, 12e930 )
  First-chance exception in DataAgent.exe (KERNEL32.DLL): 0xE06D7363: Microsoft C++ Exception.

The program goes fine when I don't run it in debug mode (well, except for the memory creep, of course!)

Failing on RtlFreeHeap sounds suspicious to me - am I doing something stupid??? Is it something to do with with way I am passing in the inRecordset param? Is it wise to call RtlFreeHeap myself, explicity?


bool DatabaseManager::FindRecord(LPTSTR TableName, LPTSTR sqlCriterion, _RecordsetPtr &inRecordset )
{
    if( ptrConnection == NULL )
    {
         sLastErrorDescription = L"A database connnection has not been established";
         return false;
    }
    if( inRecordset == NULL )
    {
         sLastErrorDescription = L"The supplied recordset was uninstantiated";    
         return false;
    }
   
    /* construct SQL query, using the given criteria */
    _bstr_t sqlQuery("SELECT * FROM ");
    sqlQuery += _bstr_t(TableName);
    sqlQuery += " WHERE ";
    sqlQuery += _bstr_t(sqlCriterion);
    sqlQuery += ";";
   
    try
    {
         if( inRecordset->GetState() != adStateClosed )
         {
              inRecordset->Close();
         }

         inRecordset->CursorLocation = adUseClient;
         inRecordset->Open(sqlQuery, ptrConnection.GetInterfacePtr(), adOpenDynamic, adLockBatchOptimistic,
-1);          
         
inRecordset->PutRefActiveConnection(NULL);          
         hResult = S_OK;
         return     true;
    }
    catch( _com_error err )
    {
         sLastErrorDescription = err.Description();
         hResult = err.Error();
    }
   
    return false;    
}


As you can probably guess, I'm completely new to this ADO stuff, and any help would be greatly appreciated.

Regards,
Kieran
0
Comment
Question by:dbaser
5 Comments
 
LVL 9

Expert Comment

by:ShaunWilde
ID: 6295880
> First-chance exception

are quite common and I have not known them to be a real problem - you might want to try boundschecker to check fo com based memory leaks or implement your own IMallocSpy interface
0
 

Author Comment

by:dbaser
ID: 6300127
Apparently what I have is very common problem... a problem which looks like a bug with the ADO!

Check out:

http://groups.google.com/groups?q=%22MEMORY+LEAK%22+recordset&hl=en&safe=off&meta=site%3Dgroups%26group%3Dmicrosoft.public.*
0
 

Accepted Solution

by:
CetusMOD earned 0 total points
ID: 10662089
PAQed, with points refunded (300)

CetusMOD
Community Support Moderator
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes how to programmatically preset the "Pages per Sheet" option that's available with most printer drivers.   This setting lets you do "n-Up" printing, where two, four, or more pages are printed on each sheet of paper. If your …
With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now