Bug #3531 Prepared statement memory leak while connection is open
Submitted: 21 Apr 2004 19:09 Modified: 22 Apr 2004 8:20
Reporter: David Reed Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S2 (Serious)
Version:5.0.0 & 4.1.1a-alpha OS:Windows (Windows XP)
Assigned to: Mark Matthews CPU Architecture:Any

[21 Apr 2004 19:09] David Reed
Description:
This may be solved by #3451 but I haven't been able to verify that.  When server side prepared statements are used (via the Java JDBC driver) memory usage by the server will increase when prepared statements are used until the connection is closed.

In particular it happens when during the same connection a new PreparedStatement object is created with the same SQL.

I came across this problem in attempting to compare another vendor to MySQL and performance/maximum load/etc.  Run the following code (it creates it's own schema for the purposes of the test.)  Watch the memory usage (commit charge in the XP taskmanager) while it's running.  The mysqld will balloon way up along with the commit charge and then clear itself out when the connection is finally closed.

(Yes, I know the example code could be make nicer, but hey...)

How to repeat:
Compile and run the attached java.  If the connection string is changed so that server side prepared statements are not used then there are no problems.
[21 Apr 2004 19:09] David Reed
Sample code to recreate problem

Attachment: DemonstrateBug.java (application/octet-stream, text), 5.35 KiB.

[22 Apr 2004 7:50] Mark Matthews
Thank you for your bug report. This issue has been committed to our
source repository of that product and will be incorporated into the
next release.

If necessary, you can access the source repository and build the latest
available version, including the bugfix, yourself. More information 
about accessing the source trees is available at
    http://www.mysql.com/doc/en/Installing_source_tree.html
[22 Apr 2004 8:20] Mark Matthews
The released version of Connector/J 3.1.1 was not releasing prepared statements when .close() was called.

Please use a nightly build from http://downloads.mysql.com/snapshots.php as this bug has been fixed in the source, and will be released in 3.1.2.