Solved

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

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Suggested Solutions

Title # Comments Views Activity
Nest Related files not working in Visual Studio 4 78
What are the big features of MVC5? 4 91
WPF issue with Trigger 2 113
Windows ICD FFU Issue 4 60
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

839 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