Campbell Ritchie wrote:Depends where else the Statement object is referred to from. The real problem is that you might not close the statement if it is not in a finally block.
Ok, i close the statement in finally block but could not ignore the fact that statement.close() actually failed in database , i am taking it as database driver failed to dis-associate cursor from statement . But marking that statement explicitly afterwards as NULL would help to reclaim memory?
Would there be any consequences in application from database point of view?
Don't know. Nitesh may wish to transfer this thread to the JDBC forum because it appears database-specific.
Setting the Statement to null (not "NULL") will only make a difference if the Statement is a field, but if there are any references to that Statement object anywhere else, it won't be collected from memory. Local variabales become unreachable when they go out of scope, so the null assignment is unnecessary for a local variable. Remember: no other references.
I don't know whether there is any risk that your Statement, not being properly closed, will block the Connection from being used again, or gradually use all the available connections to that Database, thereby creating a resource leak. Don't know.