When calling jdbcTemplate.queryForRowSet(...), the corresponding SqlRowSet does not provide a method to close the underlying ResultSet resulting in a memory leak.
The workaround is to check if SqlRowSet is an instance of (https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/jdbc/support/rowset/ResultSetWrappingSqlRowSet.html) and then cast it to that, then call getResultSet().close().
Either provide a close() method or a getResultSet() method on the SqlRowSet interface.
This is reproducible in Spring 5.1.9
Comment From: jhoeller
The original 'live' ResultSet
should have been closed by JdbcTemplate
already, before handing it back to the caller, with the wrapped ResultSet
being a CachedRowSet
instance instead. What's your specific need for externally closing it? Is the cached row set holding on to resources for some reason?
Comment From: walterjwhite
I was periodically querying for new data (once / minute) and found my connection count increasing. Every time I execute queryForRowSet, I get back a new SqlRowSet instance. I haven't dug deeper to pinpoint the issue; however, once I did the above workaround, I found the connection count remaining fixed.
Comment From: jhoeller
Closing this issue since this should not be necessary according to the design. To be reopened if we get insight into why the implicit resource management does not work here.