Article View: borland.public.cppbuilder.database.ado
Article #156TADOQuery Memory Leak
From: Patrick Wong
Date: Tue, 24 Apr 2007 03:31
Date: Tue, 24 Apr 2007 03:31
103 lines
3755 bytes
3755 bytes
Dear all,
Does anyone ever experience the captioned problem? My application is having
this problem, after being run for several hours the memory usage grew
significantly, error pops up with "Virtual memory too low" and the app has
to be restarted again. The ADOQuery is created and run in a thread. Code
excerpts are something like below:
__fastcall TThreadTestDB::TThreadTestDB(bool CreateSuspended)
: TThread(CreateSuspended)
{
m_ADOConnectionTest = new TADOConnection(NULL);
m_ADOConnectionTest->LoginPrompt = false;
m_ADOConnectionTest->ConnectionString =
AnsiString("Provider=Ifxoledbc.2;Password=bar;Persist Security
Info=True;User ID=foo;Data Source=abc@dbserver");
m_ADOQueryTest = new TADOQuery(NULL);
m_ADOQueryTest->Connection = m_ADOConnectionTest;
}
//---------------------------------------------------------------------------
void __fastcall TThreadTestDB::Execute()
{
AnsiString strSQL = "select name from table1 where account=\'1234\'";
AnsiString strRtn;
//---- Place thread code here ----
CoInitialize(NULL);
if(!m_ADOConnectionTest->Connected)
m_ADOConnectionTest->Open();
do
{
if(m_ADOQueryTest->Active)
m_ADOQueryTest->Close();
m_ADOQueryTest->SQL->Clear();
m_ADOQueryTest->SQL->Add(strSQL);
m_ADOQueryTest->Prepared = true;
m_ADOQueryTest->Open();
if(m_ADOQueryTest->RecordCount > 0)
{
m_ADOQueryTest->First();
do
{
strRtn = m_ADOQueryTest->FieldByName("name")->AsString;
m_ADOQueryTest->Next();
} while(!m_ADOQueryTest->Eof);
}
}
::Sleep(100);
Application->ProcessMessages();
} while (!Terminated);
if(m_ADOQueryTest->Active)
m_ADOQueryTest->Close();
CoUninitialize();
}
//---------------------------------------------------------------------------
__fastcall TThreadTestDB::~TThreadTestDB(void)
{
if(m_ADOQueryTest != NULL)
{
m_ADOQueryTest->Close();
delete m_ADOQueryTest;
m_ADOQueryTest = NULL;
}
if(m_ADOConnectionTest != NULL)
{
m_ADOConnectionTest->Close();
delete m_ADOConnectionTest;
m_ADOConnectionTest = NULL;
}
}
Each time the m_ADOQueryTest->Open(); is executed the memory usage increases
by 10-20k, without ever drops when the query is closed. I also tried
deleting the and recreating the ADOQuery in every iteration in the do..while
loop, but it does not help.
Googling can find many threads discussing this problem, one of which is:
http://groups.google.de/group/borland.public.delphi.thirdpartytools.general/feed/atom_v1_0_topics.xml?num=50
But most of them ends without concrete solution.
I tested in both BCB6 and BDS2006 with most updated patches. I am running
the app in Windows XP.
Hope can get some kind advice here.
Cheers,
Patrick
Technical Details
Message-ID:
<462d7a19$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!proxad.net!213.200.89.82.MISMATCH!tiscali!newsfeed1.ip.tiscali.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: 10698b,f6b9f007fd37682e,start X-Google-Attributes: gid10698b,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Patrick Wong" <patrickwong@computer.org> Newsgroups: borland.public.cppbuilder.database.ado Subject: TADOQuery Memory Leak Date: Tue, 24 Apr 2007 11:31:40 +0800 Lines: 105 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.3028 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3028 X-RFC2646: Format=Flowed; Original NNTP-Posting-Host: 203.82.254.252 Message-ID: <462d7a19$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1177385497 203.82.254.252 (23 Apr 2007 20:31:37 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!proxad.net!213.200.89.82.MISMATCH!tiscali!newsfeed1.ip.tiscali.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail