Page 1 of 1

There are memory leaks after a sql query exception occured.

Posted: Mon 21 Jan 2008 12:00
by qmanla
Hi, Please help! I turned on memory leak detection option from D2007 with the following syntax:

Code: Select all

ReportMemoryLeaksOnShutDown := true;
I have created both TMyConnection and TMyQuery at TForm.Create event and freed them at TForm.Destroy. It will report memory leak if TMyQuery.Execute method runs a bad sql statement and raised an EMySqlException. In the other hand, if the sql statement is correct, there was no problem at all.

The leak message is:

Image

I tried to prevent the code breaking up by catching exceptions, but this didn't help:

Code: Select all

....
        Query.SQL.Clear;
        Query.SQL.Add(Sql);
        try
          Query.Connection.Connect;
          Query.Execute;
        except
          on e: Exception do
            LogToFile(e.Message);
        end;
....
What should I do? thanks!

Posted: Tue 22 Jan 2008 08:21
by Dimon
We can not reproduce the problem. Please send a complete small sample to dmitryg*crlab*com to demonstrate it.

Also supply us the following information
- exact version of MyDAC. You can see it in the About sheet of TMyConnection Editor;
- exact version of MySQL server and MySQL client. You can see it in the Info sheet of TMyConnection Editor.

Posted: Wed 23 Jan 2008 07:22
by qmanla
I found that the problem is probably mine. :cry: I shared single TMyConnection object to multiple TMyQuery objects which are dynamically created in threads. This memory leak might happen if one query raised exception in a thread. (If no error happens, it works quite well though... )

I just tried to get benefit from connection pooling of TMyConnection in a multi-threaded application, would you please advice a proper use? thanks!

Posted: Wed 23 Jan 2008 15:17
by Dimon
Yes, you are rigth. The memory leak was related to FetchAll=False mode. We have reproduced this problem and fixed it. This fix will be included in the next MyDAC build.

Posted: Thu 24 Jan 2008 02:36
by qmanla
thanks! Let me supply additional settings of mine FYI.

FConnector := TMyConnection.Create(nil);
FConnector.Server := '192.168.100.1';
FConnector.Port := 3306;
FConnector.Pooling := true;
FConnector.PoolingOptions.MinPoolSize := 1;
FConnector.LoginPrompt := false;
FConnector.Options.Charset := 'utf8';
FConnector.Options.Direct := true;
FConnector.Options.UseUnicode := true;