Bug #16844 Objects are not GC-d when using StoredProcedure command type.
Submitted: 27 Jan 2006 14:55 Modified: 25 Nov 2006 14:43
Reporter: Pavel Bulanov Email Updates:
Status: No Feedback Impact on me:
None 
Category:Connector / NET Severity:S2 (Serious)
Version:1.0.7 (connector) OS:Windows (Windows XP)
Assigned to: Assigned Account CPU Architecture:Any

[27 Jan 2006 14:55] Pavel Bulanov
Description:
Executing a MySQLCommand of StoredProcedure type results in objects are not garbage collected.

I create a MySQLCommand, assign CommandType.StoredProcedure to CommandType property, set up MySQLConnection add parameters.

Then I ExecuteReader to retrieve results.

Reader is used inside "using" block, as well as command and connection.

But finally I have a lot of auxiliary MySQLCommand objects left - they are not collected.

Connection is definitely closed (checked by looking at MySQL Server connections).
All objects created are explicity disposed (via using, and this works - checked with debugger).

I track the memory with memory profiler and got the following results:
1) all my objects are disposed and got collected
2) Memory is consumed by subsidiary MySQLCommand objects
3) These objects are created in the following methods (explored by Reflector):
private string StoredProcedure.GetParameterList(MySqlCommand procCmd, out string returns, string procType)
Driver.public virtual void Configure(MySqlConnection connection)
Driver.private void LoadCharacterSets()
4) In this methods created commands are not Closed or disposed directly!!

How to repeat:
Run the following code (approximate):

/// <summary>
        /// Creates new stored procedure command.
        /// </summary>
        protected static IDbCommand CreateStoredProcedure(String name)
        {
            IDbCommand result = new MySqlCommand(name);
            result.CommandType = CommandType.StoredProcedure;
            return result;
        }

using (MySQLConnection connection = new MySqlConnection(connectionString))
{
  using(IDbCommand command = CreateStoredProcedure(GetProcedureName()))
{
  command.Connection = connection;
    using (IDataReader reader = command.ExecuteReader())
                {
                    using (FieldReader fieldReader = new FieldReader(reader))
                    {
                        // some code here
                    }
                }
 }
}

Execute this many times - a number of objects never being disposed is a result.

Suggested fix:
Close connections explicit in the above methods.
[27 Jan 2006 14:56] Pavel Bulanov
By the way, MySQL server version is 5.0.15.

Connectior is of version 1.0.7, .NET framework 1.1.
[8 Feb 2006 10:53] Pavel Bulanov
Will it be paid attention to?
[18 Feb 2006 14:27] Pavel Bulanov
Hey! Is anyone here!

Does it not concern anyone?
[27 Feb 2006 1:35] Reggie Burnett
Pavel

Yes, someone is here and this does concern us. We are looking at this issue.
[27 Feb 2006 1:36] Reggie Burnett
Pavel

Yes, someone is here and this does concern us. We are looking at this issue.
[14 Apr 2006 16:02] Pavel Bulanov
How it is going?

More than 1 month have passed.
[16 May 2006 19:51] Sergei Kotlyachkov
It seems that it's not just this but whenever cmd.ExecuteReader() is called MySqlDataReader is leaving non-disposed objects.
[31 Jul 2006 8:48] Pavel Bulanov
What's the status of this bug?
[25 Oct 2006 14:43] Reggie Burnett
Pavel

What profiler are you using and can you post the code that shows the problem?

I've executed a stored procedure inside a using block and checked with the ANTS profiler and found no object not collected.  One thing you should be aware of is that the garbage collector in .NET does not run that often.  In my test, I put the code that executed the sproc inside a method and then called that method followed by a call to GC.Collect.  This will force a garbage collection and make sure that any objects that will  eventually be collected are collected immediately.  I then take a snapshot using the profiler and look for any MySQL related objects.
[26 Nov 2006 0:00] Bugs System
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".