Skip to content

PgResultSet.close() should clear member thisRow and rowBuffer #3383

@reallyinsane

Description

@reallyinsane

Describe the issue
org.postgresql.jdbc.PgResultSet.close() does not release reference to thisRow causing memory leak when connection is pooled.

Driver Version?
All versions.

Java Version?
Not relevant.

OS Version?
Not relevant.

PostgreSQL Version?
Not relevant.

To Reproduce

  • have a connection from a pool
  • create and execute a statement returning a ResultSet with only one row
  • call ResultSet.next() to move to the first row
  • do not call ResultSet.next() a second time
  • call ResultSet.close()

Expected behaviour
The reference to thisRow should be cleared as this contains data from the first row. After calling close() the ResultSet cannot be used anymore and especially when the row contains large data memory should be released as soon as possible.

thisRow is cleared only if another ResultSet.next() is called and the end of the ResultSet is identified. It will be cleared also when ResultSet.afterLast() is called. But this is not possible for a TYPE_FORWARD_ONLY ResultSet.

PgResultSet.closeInternally() could be changed to

protected void closeInternally() throws SQLException {
  // release resources held (memory for tuples)
  rows = null;
  thisRow = null;
  rowBuffer = null;
  JdbcBlackHole.close(deleteStatement);
  deleteStatement = null;
  if (cursor != null) {
    cursor.close();
    cursor = null;
  }
  closeRefCursor();
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions