Re: Memory "leaking" from ADO!!! Help!
From: Roy Fine (rlfine_at_twt.obfuscate.net)
Date: 06/09/04
- Next message: William \(Bill\) Vaughn: "Re: Connection Best Practice"
- Previous message: Roy Fine: "Re: Memory "leaking" from ADO!!! Help!"
- In reply to: Sander Verhagen: "Memory "leaking" from ADO!!! Help!"
- Next in thread: Sander Verhagen: "Re: Memory "leaking" from ADO!!! Help!"
- Messages sorted by: [ date ] [ thread ]
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;
}
- Next message: William \(Bill\) Vaughn: "Re: Connection Best Practice"
- Previous message: Roy Fine: "Re: Memory "leaking" from ADO!!! Help!"
- In reply to: Sander Verhagen: "Memory "leaking" from ADO!!! Help!"
- Next in thread: Sander Verhagen: "Re: Memory "leaking" from ADO!!! Help!"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|