locked
ADO Memory Leak RRS feed

  • Question

  • I have a c++ program compiled and running on Win7. I am using

    [code]#import "C:\Program Files (x86)\Common Files\System\ado\msado60.tlb" no_namespace rename("EOF", "EndOfFile")[/code]

    When I make a sql call to INSERT a record, and my sql statement does not require any return data, I get a memory leak.

    EnterCriticalSection(&m_main_cs); _RecordsetPtr pRecordPtr = NULL;

    _ConnectionPtr pConn = NULL;

    //this gets the global interface structure I use dbc = globalCookie.getCookie(db, &session); if( dbc.sConnectString.GetLength() > 0 ) { hr = dbc.igt->GetInterfaceFromGlobal (dbc.dwConnectionCookie, __uuidof(_Connection), (void **) &pConn); if( hr == S_OK ) { pRecordPtr = pConn->Execute((_bstr_t) (session.sSqlStatement),NULL, adCmdText|adExecuteNoRecords); }


    pRecordPtr always comes back NULL (sinve I requested adExecuteNoRecords) as expected. Putting this in a loop doing thousands of inserts, you can see the memory get consumed.
    • Changed type Papy Normand Wednesday, October 24, 2012 8:35 PM It was a real question
    Monday, October 22, 2012 4:37 PM

Answers

  • It turns out to have been a bug on my part. I did not set a smart pointer to NULL when I was done with it. globalCookie was an array of structures I used to store connection information. I used the RegisterInterfaceGlobal functions to allow me to use a single connection for multiple (threaded) DB calls

    My bug was.....

    _variant_t avarData;

    ....

    avarData = pRs->GetRows(adGetRowsRest);

    ...

    HRESULT hr = SafeArrayGetUBound(avarData.parray, 2, &lUbound);

    ...

    avarData.Clear();

    avarData = NULL; //will leak memory if we don't do this to any "smart" pointer

    Steve
    • Edited by SteveInHouston Wednesday, October 24, 2012 7:35 PM typo
    • Marked as answer by Papy Normand Wednesday, October 24, 2012 8:36 PM
    Wednesday, October 24, 2012 7:34 PM

All replies

  • Hello,

    Do you know this link ?

    http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/01dee69f-bf5f-4ec6-8a1d-85bcbef2a35c

    Please, could you explain more exactly your problem ?

    I have used VC++ 6.0 from its release time upto 2003 ( when VC# was released and the disappearance of memory leaks ), but i have not understood how you are connecting and especially towards what.

    Are you trying to connect to a database ( which one , SQL Server,...) ?

    How is defined globalCookie ?

    Have a nice day


    Mark Post as helpful if it provides any help.Otherwise,leave it as it is.

    Wednesday, October 24, 2012 6:41 PM
  • It turns out to have been a bug on my part. I did not set a smart pointer to NULL when I was done with it. globalCookie was an array of structures I used to store connection information. I used the RegisterInterfaceGlobal functions to allow me to use a single connection for multiple (threaded) DB calls

    My bug was.....

    _variant_t avarData;

    ....

    avarData = pRs->GetRows(adGetRowsRest);

    ...

    HRESULT hr = SafeArrayGetUBound(avarData.parray, 2, &lUbound);

    ...

    avarData.Clear();

    avarData = NULL; //will leak memory if we don't do this to any "smart" pointer

    Steve
    • Edited by SteveInHouston Wednesday, October 24, 2012 7:35 PM typo
    • Marked as answer by Papy Normand Wednesday, October 24, 2012 8:36 PM
    Wednesday, October 24, 2012 7:34 PM
  • Hello,

    I have been surprised twice by your reply.

    1- because of your quickness to reply  ( thanks )

    2- because you recognize that itss a bug in your code ( what's very rare ) and you gave an explanation which was easy to understand for me who has forgotten most of my knowledges about VC++ 6.0 ( after 9 years, it is logical ).

    It is why i mark your post as answer ( this will not give you any point ) and as helpful ( +5 for you in theory ) for your now correct code .

    A little advice for a next time : in the toolbar just above the box in which you write your question or reply, click on the icon just on the right side of the icon labelled HTLM ( if you pass your mouse on this icon, you will see to appear the "Insert Code Block" message. A new form will appear with the Insert Code Block label. Don't forget to choose the correct language in the combobox ( usually for you C++ but for Transct_SQL statements, it would be Sql ). Write your code in the left panel ( in a formatted way ) and click on the Preview button to see how your code will appear in your post. If you are satisfied , click on the Insert button to insert your code in your post. You will see that it is easier and more pleasant to read instead to put your code directly in your post. And , after a number of inserted codes, you will have more points and a bronze medal.Gadget maybe , but i have always a good remembrance of my 1st medals.

    I hope to see you another time on this forum ( or on another one )

    Have a nice day


    Mark Post as helpful if it provides any help.Otherwise,leave it as it is.

    Wednesday, October 24, 2012 8:32 PM
  • Thanks! I was in a hurry when I posted, trying to get out of work before traffic got too bad :-))

    I'll do better code posting next time :-)

    Steve

    • Proposed as answer by Sixfore Wednesday, July 24, 2013 2:17 PM
    Thursday, October 25, 2012 12:06 PM