Index: java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java =================================================================== --- java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java (revision 600678) +++ java/engine/org/apache/derby/impl/jdbc/EmbedResultSet.java (working copy) @@ -127,7 +127,8 @@ /** This activation is set by EmbedStatement for a single execution Activation. Ie. - a ResultSet from a Statement.executeQuery(). + a ResultSet from a Statement.executeQuery() or + a ResultSet that is now a dynamic result set. In this case the closing of this ResultSet will close the activation or the finalization of the parent EmbedStatement without it being closed will mark the Activation as unused. @@ -4397,6 +4398,16 @@ this.owningStmt = owningStmt; this.localConn = owningStmt.getEmbedConnection(); + + // The activation that created these results now becomes + // a single use activation so it will be closed when this + // object is closed. Otherwise the activation would + // only be closed on garbage collection for any + // dynamic result set created by a PreparedStatement + // or CallableStatement. Dynamic result sets created + // by Statement objects will already be marked as + // single use. + this.singleUseActivation = theResults.getActivation(); } /* Index: java/engine/org/apache/derby/impl/jdbc/EmbedStatement.java =================================================================== --- java/engine/org/apache/derby/impl/jdbc/EmbedStatement.java (revision 600678) +++ java/engine/org/apache/derby/impl/jdbc/EmbedStatement.java (working copy) @@ -326,6 +326,12 @@ * well, even though prepared statements reuse activations, since * getGeneratedKeys() uses a single-use activation regardless * of statement type. + *
+ * Dynamic result sets (those in dynamicResults array) need not + * be handled here as they will be handled by the statement object + * that created them. In some cases results will point to a + * ResultSet in dynamicResults but all that will happen is that + * the activation will get marked as unused twice. */ protected void finalize() throws Throwable { super.finalize();