🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.database.ado
Article #158

Re: TADOQuery Memory Leak

#158
From: Vassiliev V. V.
Date: Tue, 24 Apr 2007 10:09
119 lines
4670 bytes
Try to place code from constructor and destructor into Execute method - this 
way they will be executed in your thread, not in main thread (or thread 
where you create TThreadTestDB object).

//------------------------------------------
Regards,
Vassiliev V. V.
http://www.managed-vcl.com - using .Net objects in Delphi for Win32 +
ADO.Net
http://www.oledbdirect.com - The fastest way to access MS SQL Server,
MS Jet (Access) and Interbase (through OLEDB)


"Patrick Wong" <patrickwong@computer.org> �������/�������� � �������� 
���������: news:462d7a19$1@newsgroups.borland.com...
> 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: <462dd7ee$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <462d7a19$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10698b,f6b9f007fd37682e
X-Google-Attributes: gid10698b,public
X-Google-Language: ENGLISH,ASCII
From: "Vassiliev V. V." <support@oledbdirect.com>
Newsgroups: borland.public.cppbuilder.database.ado
References: <462d7a19$1@newsgroups.borland.com>
Subject: Re: TADOQuery Memory Leak
Date: Tue, 24 Apr 2007 14:09:45 +0400
Lines: 121
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; Response
X-Antivirus: avast! (VPS 000735-2, 23.04.2007), Outbound message
X-Antivirus-Status: Clean
NNTP-Posting-Host: 85.93.138.132
Message-ID: <462dd7ee$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1177409518 85.93.138.132 (24 Apr 2007 03:11:58 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail