Memory Leak with SQLQuery and C++ Builder 2006

Discussion of open issues, suggestions and bugs regarding usage of dbExpress drivers for MySQL in Delphi and C++Builder
Post Reply
styletronic
Posts: 8
Joined: Fri 10 Mar 2006 14:21

Memory Leak with SQLQuery and C++ Builder 2006

Post by styletronic » Sun 17 Jun 2007 22:31

We are using the latest CRLabs dbExpress Driver 3.20.5 under BDS2006 C++ Builder. In our application we are using TSQLConnection and TSQLQuery. Database Server = MySQL 5.0.41.

I have noticed, that there is a memory leak when you frequently open and close a simple SQLQuery. The memory increases every second, until the system goes out of memory :!:

Our example:

SQLConnection = new TSQLConnection(NULL);
SQLConnection->ConnectionName = "MySQL Direct by Core Lab";
SQLConnection->DriverName = "MySQL Direct by Core Lab";
SQLConnection->GetDriverFunc = "getSQLDriverMySQLDirect";
SQLConnection->LibraryName = "dbexpmda30.dll";
SQLConnection->KeepConnection = true;
SQLConnection->LoginPrompt = False;
SQLConnection->Params->Add("BlobSize=-1");
SQLConnection->Params->Add("HostName="+AnsiString(mysql_host));
SQLConnection->Params->Add("DataBase="+AnsiString(mysql_db));
SQLConnection->Params->Add("DriverName=MySQL Direct by Core Lab");
SQLConnection->Params->Add("User_Name="+AnsiString(mysql_user));
SQLConnection->Params->Add("Password="+AnsiString(mysql_pass));
SQLConnection->Params->Add("FetchAll=True");
SQLConnection->Params->Add("EnableBoolean=False");
SQLConnection->VendorLib="not used";
SQLConnection->Connected=true;
SQLQuery = new TSQLQuery(NULL);
SQLQuery->SQLConnection = SQLConnection;

while(beenden==false)
{
SQLQuery->Active=false;
SQLQuery->SQL->Clear();
SQLQuery->SQL->Add("SELECT * FROM DEVICES");
SQLQuery->Active=true;
Sleep(1000);
}


What could be wrong here?

Antaeus
Posts: 2098
Joined: Tue 14 Feb 2006 10:14

Post by Antaeus » Tue 19 Jun 2007 11:59

I tested this code with several tables on my server, but could not reproduced the problem. Please prepare a complete small test sample to reproduce the prolem. Firstly it should create a database with required objects in it. You can send this sample to me at evgeniyd*crlab*com.

styletronic
Posts: 8
Joined: Fri 10 Mar 2006 14:21

Post by styletronic » Fri 22 Jun 2007 00:24

Hi Antaeus!

I have testet it now with
1) Borland C++ Builder 2006 and Crlab 3.20.5 dbexpmda30.dll
2) Codegear C++ Builder 2007 and Crlab 4.0.0.1 dbexpmda40.dll

Driver: Corelab Mysql Direct
MySQL Server version: 5.0.41
Windows server version: Windows 2003 Server R2
We are using TSQLConnection instead of TCRSQLConnection.
TSQLConnection and TSQLQuery are created dynamically as i posted in the code before.

In both cases the application memory increases by 4K steps after ever SQL execution or opening and closing a SQLQuery.
I am 100% sure that this is a DBExpress Bug!!

Regards, Martin

Antaeus
Posts: 2098
Joined: Tue 14 Feb 2006 10:14

Post by Antaeus » Sat 23 Jun 2007 06:58

We still cannot reproduce the problem. Can you reproduce it with one of DbxMda demo projects? If you cannot, we need your complete test case to it as it may be related to columns data type and some other things. A sample like I asked in my previous post should be helpful.

styletronic
Posts: 8
Joined: Fri 10 Mar 2006 14:21

Post by styletronic » Wed 15 Aug 2007 20:56

I sent you a test project by mail, but it is very easy to reproduce:

Create this table:
--------------------------------------------------------------------------------
CREATE TABLE `test` (
`DATASET` int(11) NOT NULL,
`VALUE` int(11) NOT NULL,
PRIMARY KEY (`DATASET`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
--------------------------------------------------------------------------------
INSERT INTO `test` (`DATASET`, `VALUE`) VALUES
(1, 1000),
(2, 2000),
(3, 3000),
(4, 4000),
(5, 5000);
--------------------------------------------------------------------------------

Then call this routine:

void __fastcall TForm1::Button1Click(TObject *Sender)
{
for(int i=0; iSQLQuery1->Close();
Form1->SQLQuery1->SQL->Clear();
Form1->SQLQuery1->SQL->Add("SELECT * FROM TEST");
Form1->SQLQuery1->Open();
}
}

On every execution, memory will increase about 300Kbyte.

styletronic
Posts: 8
Joined: Fri 10 Mar 2006 14:21

Post by styletronic » Wed 15 Aug 2007 21:19

Update: I have tested the same procedure with MyDAC 5.10 => Here the issue doesn’t happen!

Regards, Martin

Antaeus
Posts: 2098
Joined: Tue 14 Feb 2006 10:14

Post by Antaeus » Tue 21 Aug 2007 07:32

Thank you for your sample, but I still cannot reproduce the problem. I used the last DbxMda (version 4.0.0.2) for test. It is likely that the problem has been fixed in the last DbxMda.

Post Reply