Should we reference Objects to null in finally block while Objects are in local scope of method? What are the performance issues resolved by doing so?
code:
Map<String, Map<String, String>> getData(Map<String, String> params) {
StringBuilder query = new StringBuilder(); // Construct query using it
ResultSet rs = null;
try {
rs = DataUtil.getData(query);
while(rs.next) {
// store data in return Map
}
} catch(ConnectionException ce){
ce.printStackTrace();
} catch(Exception e) {
e.printStackTrace();
} finally {
rs = null;
query = null;
}
}
Here, freeing up rs
and query
seems to fulfill no purpose as they are automatically valid for garbage collection after method execution. Any help would do great.