code:
--------------------------------------------------------------------------------
Connection dbConn = // whatever
String sql = "select * from very_big_table";
Statement stmt = dbConn.createStatement(sql);
ResultSet rs = stmt.executeQuery();
while (rs.next())
{
String col1 = rs.getString(1);
}
With the String coll inside the while loop - a NEW string is created every iteration
Garbage collection may/may NOT get a chance to recover obsolete Strings
String col1 = "";
while (rs.next())
{
col1 = rs.getString(1);
}
With String coll outside the loop - only ONE instance of a String is created its REFERENCE is re-used at every iteration of the while loop
(NOT completely true with Strings - but pretty much so)