Forums Register Login

Statement Closure in a loop: performance and memory management

+Pie Number of slices to send: Send
Hi All,
This is more related to performance and memory management. I have following scenario:



Here, After processing the resultset for one select query, the selectStatement reference is being assigned to new select statement and further resultset reference gets a new Resultset Object.
What happens to previous Statement & Resultset Objects?
What I understand is they become candidate for GC.
But my question is shall I close them before they get assigned new object references? From performance/memory management point of view, does it make any difference?

Thanks & Regards,
Jigar.

+Pie Number of slices to send: Send
I would close them, as they are using up database resources whilst open.
also it is best to put the closes in a finally block so it happens even if you have an exception.
+Pie Number of slices to send: Send
You need to close the statement object that's why it has a close method and relying to GC is not enough. At some point you will encounter an exception if you do not close the statement object. ResultSet implicitly closed when you close the statement.
Is this the real life? Is this just fantasy? Is this a tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 733 times.
Similar Threads
nested ResultSets
best programming practises of JDBC
To Nikhil Pendharkar for IBM 287
GC question..........
Bug in JDBC ? Simple Select statement not returning a resultSet
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 02:38:04.