Re: Memory "leaking" from ADO!!! Help!

From: Roy Fine (rlfine_at_twt.obfuscate.net)
Date: 06/09/04


Date: Tue, 8 Jun 2004 21:27:43 -0400

Sander,

I have distilled the relevant parts of your application down to the code
below. Here are the coments that I would have:

1) why are you setting the default cursor location of the connection to
adUseclient? For the most part you are fetching and loading data into a
local store - there is no reason to ALSO populate a client side cursor.

2) The AllocSysString method of CString does exactly what the SysAllocString
API call does - create a BSTR and copies the data to it. You must call the
SysFreeString method somewhere. Better yet, dispense with the CString here
and use the COM Automation helper class - the _bstr_t. It has cleanup and
resource management in the class destructor.

3) The RecordsAffected parameter is net set during a SQL Select statement -
only during a DML statement, Better to just send in a NULL

4) Why not build the Recorset the old-fashioned way -set the command tst,
set the cursor location, set the connection reference, then call Open
method?

5) I didn't see anything obvious with the code that would indicate a memory
leak. You may want to have another look at the code that builds the memory
structure.

regards
roy fine

/* ****************************** */
#define SCCS BOOL
#define SUCCESS FALSE
#define FAIL TRUE

/* ****************************** */
SCCS Open(LPCSTR connectionstring) {
::CoInitialize(NULL);
m_pConnection.CreateInstance(__uuidof(Connection));
m_pConnection->Open(connectionstring, "", "",adConnectUnspecified);
m_pConnection->CursorLocation = adUseClient;
return SUCCESS;
}

/* ****************************** */
SCCS LoadRecords( ... ){
CString sql;
COleVariant RecordsAffected;
_RecordsetPtr set = m_pConnection->Execute(
sql.AllocSysString(),RecordsAffected, adCmdText );
while( !set->EndOfFile ) {
         /* put the retrieved records into memory objects, here */
         /* I'm pretty darn quite sure that this isn't where the problem is
*/
       }
set->Close();
set = 0;
return SUCCESS;
}



Relevant Pages

  • Re: Memory "leaking" from ADO!!! Help!
    ... why are you setting the default cursor location of the connection to ... The AllocSysString method of CString does exactly what the SysAllocString ... SCCS Open{ ... return SUCCESS; ...
    (microsoft.public.sqlserver.programming)
  • Re: Memory "leaking" from ADO!!! Help!
    ... why are you setting the default cursor location of the connection to ... The AllocSysString method of CString does exactly what the SysAllocString ... SCCS Open{ ... return SUCCESS; ...
    (microsoft.public.access.adp.sqlserver)
  • Re: Memory "leaking" from ADO!!! Help!
    ... why are you setting the default cursor location of the connection to ... The AllocSysString method of CString does exactly what the SysAllocString ... SCCS Open{ ... return SUCCESS; ...
    (microsoft.public.vc.database)
  • he will cease alternatively, unless Eve hires atoms toward Maifys dirt
    ... Otherwise the hen in Agha's success might conduct some ... suggestions document in connection with furious ... Every emotional selected blacks will wearily shift the contributions. ... apart from the distinguished librarys, ...
    (sci.crypt)
  • Re: C++ help needed!
    ... s1 is not char*, it is CString! ... int pos = sStr.Find; ... use just (ptr - strings) of them ... success = false; ...
    (microsoft.public.vc.mfc)