Bug #86159 JConnector driver does not free closed objects
Submitted: 2 May 2017 13:08 Modified: 3 Jun 2017 12:20
Reporter: NOT_FOUND O Email Updates:
Status: No Feedback Impact on me:
Category:Connector / J Severity:S2 (Serious)
Version:5.1.42 OS:Any
Assigned to: Assigned Account CPU Architecture:Any

[2 May 2017 13:08] NOT_FOUND O
I have a Java application which parses JSON messages from an ActiveMQ message queue.
The application then calls a stored procedure in the database to insert values pulled from the JSON into the database.

All of this works, but after a length of time, I see the memory consumption of my application gradually climbing. After taking a heap dump and parsing it using the Eclipse Memory analyser tool, it points to JDBC42CallableStatements as the leak suspect.

Each heap dump has greater numbers of JDBC CallableStatements etc..
There were 200,000 instances of CallableStatements and matching numbers of Resultsets, ParseInfo objects in one dump I took.

IntelliJ has a MemoryView plugin which shows that the number of CallableStatement objects in memory does not decrease after I close them. I get that they may still exist until Garbage collection but analysis of the Heap shows that these objects are never considered for destruction. There is no destroy() method, so it seems like these objects just continue to increase.

Because I'm processing potentially millions of messages, I keep a persistent Database Connection open, but I have also tried opening and closing the Connection object each time to call the stored procedure and I see the same behaviour with it. 

Stepping through the code below with IntelliJ memory viewer open showed the class count increase and never decrease even after I call system.gc


I'm using the latest 

ConnectorJ mysql-connector-java-5.1.42-bin


JDK C:\Program Files\Java\jdk1.8.0_131\bin\java

How to repeat:
Here's my code. I've tried CallableStatements declared at both the Class and function level.

    private int db_callsrored proc(int someint, String somestring){
        int retval=0;
        String sp_name = "mydb.sp_insertdata";
        String query = "{CALL " + sp_name  +"(?,?,?)}";
        if (dbconnected){
            int igwid = 0;
            l4j.info("Prepare Database Sp->" + sp_name);
                CallableStatement cs;
                cs = dbconnection.prepareCall(query);
                cs.setInt("vRVPIN", rvpin);
                cs.setString("vsrtID", somestring);
                cs.setInt("vintID", 0);

                cs.registerOutParameter("vintID", Types.INTEGER);

                l4j.info("Executed Database Sp->" + sp_name);

                retval = cs.getInt("vintID");


                //retval = Integer.toString(igwid);
                l4j.info("Got id from Db->" + retval);
            }catch(MySQLDataException e){
                l4j.error("MySQLDataException Exception calling " + sp_name, e);
            }catch (SQLException e) {
                l4j.error("SQLException Error calling " + sp_name, e);
            } catch (NullPointerException e){
                l4j.error("NullPointerException Error calling " + sp_name, e);
            l4j.error("Unable to execute " + sp_name +  " - no Database connection");

        return retval;
[3 May 2017 12:20] Chiranjeevi Battula
Hello  !!,

Thank you for the bug report.
Could you please provide repeatable test case (exact steps, connection string, MySQL version etc. - please make it as private if you prefer) to confirm this issue at our end?

[4 Jun 2017 1: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".