Bug #32187 Memory leak related with MySql connector and Mono
Submitted: 8 Nov 2007 14:57 Modified: 3 Dec 2007 8:08
Reporter: David Cantin Email Updates:
Status: Not a Bug Impact on me:
None 
Category:Connector / NET Severity:S2 (Serious)
Version: OS:Any (Tested un Windows XP and Ubuntu 7.10)
Assigned to: CPU Architecture:Any

[8 Nov 2007 14:57] David Cantin
Description:
I got the following class that leak quite much :

using System;
using System.Data;
using MySql.Data.MySqlClient;

namespace MySqlRelatedMemoryLeakTestCase {
        
public class MySqlQueryLauncher {
        
        IDbConnection dbConn; 
        
        public MySqlQueryLauncher() {

                string connectionString =
"Server=localhost;Database=mysql;User ID=user;Password=password;";
                                                
                this.dbConn = new MySqlConnection(connectionString);
                this.dbConn.Open();
                
                this.StressMySql();
        }
        
        private void StressMySql() {
                
                while(true) {
                
                        IDbCommand cmd = this.dbConn.CreateCommand();
                        cmd.CommandText = "SELECT user FROM user";
                        
                        IDataReader reader = cmd.ExecuteReader();
                        
                        while(reader.Read()) {
                                string user = (string) reader["user"];
                        }
                        
                        reader.Close();
                        cmd.Dispose();
                        
                }
        }
}

}

Let this loop run and watch the memory usage of the process...

So, maybe I'm doing something wrong or maybe there is a real leak some
where in the mono code or in the MySql one.

In this example, I use mono 1.2.4 with MySqlConnector (MySql.Data.dll)
5.0.8.1. On the server side, I got MySql 5.0.21-3ubuntu1 (default
install) on ubuntu Dapper Drake.

I have have a simple test case (a monodevelop solution) that trigger the
problem that I can send on request.

How to repeat:
Run the code supplied in the description
[1 Dec 2007 5:24] David Cantin
Finally, the bug was probably on the mono side.

I re-run my test case against the pre-release of mono-1.2.6 for Windows and the leak do not append any more.

I took the preview version from there : http://mono.ximian.com/monobuild/preview/download-preview/
[3 Dec 2007 8:08] Tonci Grgin
David, thanks for info provided and your interest in MySQL.