Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2001-07-17
5
Medium Priority
?
554 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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

This tutorial is about how to put some of your C++ program's functionality into a standard DLL, and how to make working with the EXE and the DLL simple and seamless.   We'll be using Microsoft Visual Studio 2008 and we will cut out the noise; that i…
This article shows how to make a Windows 7 gadget that extends its U/I with a flyout panel -- a window that pops out next to the gadget.  The example gadget shows several additional techniques:  How to automatically resize a gadget or flyout panel t…
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…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

604 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