Solved

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

Posted on 2001-07-17
5
544 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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

This article shows how to make a Windows 7 gadget that accepts files dropped from the Windows Explorer.  It also illustrates how to give your gadget a non-rectangular shape and how to add some nifty visual effects to text displayed in a your gadget.…
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

705 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

18 Experts available now in Live!

Get 1:1 Help Now