Board index » cppbuilder » TADOQuery Memory Leak
Patrick Wong
![]() CBuilder Developer |
TADOQuery Memory Leak2007-04-24 11:31:40 AM cppbuilder78 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: groups.google.de/group/borland.public.delphi.thirdpartytools.general/feed/atom_v1_0_topics.xml 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 |