Solved

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

Posted on 2001-07-17
5
549 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article shows a few slightly more advanced techniques for Windows 7 gadget programming, including how to save and restore user settings for your gadget and how to populate the "details" panel that is displayed in the Windows 7 gadget gallery.  …
After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

730 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