[ 
https://issues.apache.org/jira/browse/CASSANDRA-3244?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13113151#comment-13113151
 ] 

Patricio Echague commented on CASSANDRA-3244:
---------------------------------------------

Hi Rick. I browsed Spring source code, and I saw the JDBCTemplate creates a 
statement every time a query is executed.

This is a snippet of code:
{code}
        
//-------------------------------------------------------------------------
        // Methods dealing with static SQL (java.sql.Statement)
        
//-------------------------------------------------------------------------

        public <T> T execute(StatementCallback<T> action) throws 
DataAccessException {
                Assert.notNull(action, "Callback object must not be null");

                Connection con = DataSourceUtils.getConnection(getDataSource());
                Statement stmt = null;
                try {
                        Connection conToUse = con;
                        if (this.nativeJdbcExtractor != null &&
                                        
this.nativeJdbcExtractor.isNativeConnectionNecessaryForNativeStatements()) {
                                conToUse = 
this.nativeJdbcExtractor.getNativeConnection(con);
                        }
                        stmt = conToUse.createStatement();   // <-------- here 
---------
                        applyStatementSettings(stmt);
                        Statement stmtToUse = stmt;
                        if (this.nativeJdbcExtractor != null) {
                                stmtToUse = 
this.nativeJdbcExtractor.getNativeStatement(stmt);
                        }
                        T result = action.doInStatement(stmtToUse);
                        handleWarnings(stmt);
                        return result;
                }
{code}



> JDBC CassandraConnection may lead to memory leak when used in a pool
> --------------------------------------------------------------------
>
>                 Key: CASSANDRA-3244
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-3244
>             Project: Cassandra
>          Issue Type: Improvement
>          Components: Drivers
>    Affects Versions: 1.0.0
>            Reporter: Patricio Echague
>            Priority: Minor
>
> I may be wrong here but I noticed that the implementations of 
> CassandraConnection#createStatement() and 
> CassandraConnection#prepareStatement() keep(cache) the created 
> Statement/PrepareStatement internally in a List.
> They list is freed up only during CassandraConnection.close() which makes me 
> think that, if the connection object is used in a pool implementation, it 
> will lead to a memory leak as it will hold every single statement that is 
> used to interact with the DB until the connection gets closed. 

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to