Auto-close result returned from getResultSet - #781
Merged
Conversation
`ResultSet` objects returned from `Statement#executeQuery()` is closed automatically, when its parent statement is closed. Per JDBC specification: > When a Statement object is closed, its current ResultSet object, if > one exists, is also closed. Though, when a `ResultSet` is obtained from `Statement#execute()` + `Statement.getResultSet()`, such `ResultSet` was not considered to be a "current ResultSet object" because, according to the spec: > This method [`Statement.getResultSet()`] should be called only once per > result. Thus such result set was not closed automatically. Such code is used in practice and it has started to cause a memory leak (of the full materialized result set) after duckdb#533 was added. This PR fixes the leak by retaining the `ResultSet`, returned from `Statement.getResultSet()`, as a "current ResultSet object" and closing it automatically on `Statement` close. Testing: new tests added to `TestClosure` Fixes: duckdb#780
staticlibs
force-pushed
the
result_autoclose
branch
from
August 3, 2026 20:08
4522dcf to
9b04ae5
Compare
This was referenced Aug 3, 2026
staticlibs
added a commit
that referenced
this pull request
Aug 3, 2026
This is a backport of the PR #781 to `v1.5-variegata` stable branch. `ResultSet` objects returned from `Statement#executeQuery()` is closed automatically, when its parent statement is closed. Per JDBC specification: > When a Statement object is closed, its current ResultSet object, if > one exists, is also closed. Though, when a `ResultSet` is obtained from `Statement#execute()` + `Statement.getResultSet()`, such `ResultSet` was not considered to be a "current ResultSet object" because, according to the spec: > This method [`Statement.getResultSet()`] should be called only once per > result. Thus such result set was not closed automatically. Such code is used in practice and it has started to cause a memory leak (of the full materialized result set) after #533 was added. This PR fixes the leak by retaining the `ResultSet`, returned from `Statement.getResultSet()`, as a "current ResultSet object" and closing it automatically on `Statement` close. Testing: new tests added to `TestClosure` Fixes: #780
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ResultSetobjects returned fromStatement#executeQuery()is closed automatically, when its parent statement is closed.Per JDBC specification:
Though, when a
ResultSetis obtained fromStatement#execute()+Statement.getResultSet(), suchResultSetwas not considered to be a "current ResultSet object" because, according to the spec:Thus such result set was not closed automatically.
Such code is used in practice and it has started to cause a memory leak (of the full materialized result set) after #533 was added.
This PR fixes the leak by retaining the
ResultSet, returned fromStatement.getResultSet(), as a "current ResultSet object" and closing it automatically onStatementclose.Testing: new tests added to
TestClosureFixes: #780