Article View: borland.public.cppbuilder.database.ado
Article #5722Leaking memory with ADO
From: Thomas Wagener
Date: Sun, 25 Feb 2001 17:46
Date: Sun, 25 Feb 2001 17:46
73 lines
3633 bytes
3633 bytes
Hi everybody,
I have a problem with an ADO query that does not clean up properly. Perhaps
some kind soul can tell me what I am missing here.
I have included the function that is not working a expected at the bottom of
this message. The function is working as expected and I can retrieve the
documents I am looking for. However, for some reason not all of the memory
is freed when result is returned.
Let me give an example. The document I retrieve from the database (an MS SQL
server) is 5 MB in size. Thus, I would expect that the memory allocation
after the call to the function has completed is +5MB to the memory allocated
before the function is called. What I observe using the Windows 2000 task
manager is that there are additional 5MB allocated by that are not freed
when the function returns.
When stepping through the function line-by-line with the debugger the memory
allocation is as follows:
dbDocumentQuery->Open() +5MB (result set with the 5MB
dcument)
result += dbBlobField->AsVariant: +15MB (assigning the 5MB content
of the document plus Variant overhead )
After the assignment of the BLOB field to the WideString the memory
allocation drops by 10MB and remains constant. It looks like the DataSet
obtained from the TADOQuery is not de-allocated properly. Can anybody tell
me what I am doing wrong or if there is a workaround for this problem?
Thank you,
Thomas
WideString __fastcall TQueryProcessor::doDisplaydoc(const AnsiString&
queryString)
{
WideString result;
TADOQuery* dbDocumentQuery = new TADOQuery(0);
try{
// Setting up the query works just fine and the query is executed
without any
// problems. dbConnectionPtr is a TADOConnection that is reused
throughout
// the whole unit.
dbDocumentQuery->Connection = dbConnectionPtr;
dbDocumentQuery->SQL->Text = queryString;
dbDocumentQuery->Open();
if(dbDocumentQuery->RecordCount > 0){
dbDocumentQuery->First();
while(!dbDocumentQuery->Eof){
result += "<document did='" +
dbDocumentQuery->FieldByName("DID")->AsString + "'>";
TBlobField* docBlob =
(TBlobField*)dbDocumentQuery->FieldByName("DocContent");
// I have to use the AsVariant property because the
content of the field is unicode
result += docBlob->AsVariant;
result += "</document>";
dbDocumentQuery->Next();
} // while
} // if
} // try
__finally{
dbDocumentQuery->Close();
delete dbDocumentQuery;
dbDocumentQuery = 0;
} // __finally
return result;
}
Technical Details
Message-ID:
<3a994504_1@dnews>Path:
arc1-ca.pugleaf.net!supernews.google.com!sn-xit-03!supernews.com!logbridge.uoregon.edu!hammer.uoregon.edu!feed.textport.net!news.bnb-lp.com!bornews.borland.com!dnews!217.0.58.178Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10698b,32812cddffcee7a1,start X-Google-Attributes: gid10698b,public X-Google-ArrivalTime: 2001-02-25 10:08:12 PST From: "Thomas Wagener" <wagener@rs-system.de> Newsgroups: borland.public.cppbuilder.database.ado Subject: Leaking memory with ADO Date: Sun, 25 Feb 2001 18:46:38 +0100 Lines: 76 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4133.2400 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 NNTP-Posting-Host: 217.0.58.178 Message-ID: <3a994504_1@dnews> X-Trace: 25 Feb 2001 09:46:44 -0800, 217.0.58.178 Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-03!supernews.com!logbridge.uoregon.edu!hammer.uoregon.edu!feed.textport.net!news.bnb-lp.com!bornews.borland.com!dnews!217.0.58.178