Bug #8848 | Possible Memory Leak | ||
---|---|---|---|
Submitted: | 28 Feb 2005 17:55 | Modified: | 28 Feb 2005 18:09 |
Reporter: | Daniel Pereira | Email Updates: | |
Status: | Not a Bug | Impact on me: | |
Category: | Connector / J | Severity: | S2 (Serious) |
Version: | 3.1.7 | OS: | Tested on XP and Linux (Red Hat) |
Assigned to: | CPU Architecture: | Any |
[28 Feb 2005 17:55]
Daniel Pereira
[28 Feb 2005 18:09]
Mark Matthews
This behavior is required by the JDBC specification. Statements are 'alive' until you either close them, or the connection closes them. To do this, the driver needs to maintain a reference to any open statement instance, even after it has left your application's scope. Unfortunately, finalizers are being discouraged by Sun and others, as they impact GC throughput, so the answer is not to add a finalizer to these classes to automatically close them if the application forgets to do so. Given that starting with MySQL-5.0, PreparedStatements may have server-side references, implementing a finalizer that would close the server resources as well is a recipe for deadlock. You should close open statements yourself (as is required by the JDBC specification), or if you have an application that does a bad job of this, use 'dontTrackOpenResources=true' in your JDBC url, which will cause the JDBC driver to not be in compliance with the JDBC specification, but will cause the driver not to keep track of statements on a per-connection basis, so that once an instance of a statement goes out of scope, it is free to be GC'd.