If you were to use a StringBuffer instead of a string, javac is smart
enough to optimize so that the object is created outside of the loop.
However, since you have chosen to use a String here, and Strings are
immutable, a new String object must be created (without your interference)
every time you assign a new value to the String. This will happen
regardless of whether the String col variable was declared inside or
outside of the loop.

In theory each String is eligible for garbage collection immediately after
all handles to the object have been lost; here, when the assignment
statement is performed. But the objects aren't guaranteed to be garbage
collected at all. This is something to consider, depending on how many
instances of your servlet will run concurrently.


>         // load driver, connect to dbURL, create Statement, execute query.
>         ResultSet rs;
>         while (rs.next()) {
>                 String col = rs.getString(1);
>         }

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to