db-derby-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Knut Anders Hatlen (JIRA)" <derby-...@db.apache.org>
Subject [jira] Commented: (DERBY-1142) Metadata calls leak memory
Date Thu, 23 Mar 2006 15:53:20 GMT
    [ http://issues.apache.org/jira/browse/DERBY-1142?page=comments#action_12371579 ] 

Knut Anders Hatlen commented on DERBY-1142:

Thanks for looking into this, Anders!

The activation is removed from acts when Activation.close() is
called. Normally, EmbedResultSet.close() calls theResults.finish()
(implemented in BasicNoPutResultSetImpl), which calls
activation.close(). From BasicNoPutResultSetImpl.finishAndRTS():

  if (isTopResultSet && activation.isSingleExecution())

For the metadata query, isSingleExecution() returns false, hence
activation.close() isn't called when the result set is closed. It
seems like isSingleExecution() is true only if a Statement is used,
but the metadata query uses a PreparedStatement.

As you noticed, the PreparedStatement is not being closed. However, I
found this in EmbedResultSet.close():

    if (forMetaData) {
      LanguageConnectionContext lcc = getEmbedConnection().getLanguageConnection();
      if (lcc.getActivationCount() > 1) {
        // we do not want to commit here as there seems to be other
        // statements/resultSets currently opened for this connection.
      } else if (owningStmt != null) {
        // allow the satement to commit if required.
    } else if (owningStmt != null) {
      // allow the satement to commit if required.

Could we solve the problem by invoking owningStmt.close() when
forMetaData is true and the activation count is not greater than one?

> Metadata calls leak memory
> --------------------------
>          Key: DERBY-1142
>          URL: http://issues.apache.org/jira/browse/DERBY-1142
>      Project: Derby
>         Type: Bug
>   Components: JDBC
>     Versions:,
>     Reporter: Knut Anders Hatlen
>     Priority: Minor
>  Attachments: metadataloop.java
> When calling a DatabaseMetaData method that returns a ResultSet,
> memory is leaked. A loop like this (using the embedded driver)
>   while (true) {
>     ResultSet rs = dmd.getSchemas();
>     rs.close();
>   }
> will eventually cause an OutOfMemoryError.

This message is automatically generated by JIRA.
If you think it was sent incorrectly contact one of the administrators:
For more information on JIRA, see:

View raw message