You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Memory leak: Statement.getResultSet() result never freed when statement is closed #780
That means e.g. this standard JDBC 4.3 compliant code leaks the native result per query:
Connectionc = DriverManager.getConnection("jdbc:duckdb:");
PreparedStatements = c.prepareStatement("SELECT 1");
for (inti = 0; i < 100_000; i++) {
s.execute();
ResultSetrs = s.getResultSet(); // ownership detached from s// rs never closed — closing a Statement must close its ResultSets (JDBC 4.3)
}
s.close();
// each iteration orphans a MaterializedQueryResult; native memory grows linearly
Any JDBC wrapper that uses execute() + getResultSet() and relies on statement close to clean up results leaks on every query — next.jdbc and Spring's JdbcTemplate both do this. In our production service this retained a MaterializedQueryResult per query, growing native memory (invisible to the JVM heap and to duckdb_memory()) until OOM.
Note
I spent many many hours trying to figure out a memory leak issue for my OSS tool: https://github.com/o11ylite/o11ylite.
I initially thought it was upstream DuckDB issue, which I did discover one/two leaks and @dentiny helped fixing them but it turned out leak still happens after v1.5.5. And that's when I start suspecting my Clojure/Java harness is the culprit.
Activity
Auto-close result returned from getResultSet
staticlibs commentedon Aug 3, 2026
Hi, thanks for the report and for the deep investigation that led to it!
I believe this code is not strictly-speaking "JDBC compliant" (see longer description in #781) and instead it should be:
Though, obviously the pedantic reading of the spec is not helpful, I filed #781 with the fix and will do a 1.5.5.1 update with it included shortly.
Auto-close result returned from getResultSet (1.5)
zhming0 commentedon Aug 4, 2026
Thank you so much for the quick fix @staticlibs. I've tested the new version, my app is finally memory leak free now 🥹 .