In J@whiz I found the following question
When the program reaches line 8, how many of the
String objects created in line 3 are eligible for garbage collection?
1.public void countDown()
2.{
3. for( int i = 10 ; i >= 0 ; i-- )
4.{
5.String tmp = Integer.toString( i );
6.System.out.println( tmp );
7. }
8.System.out.println("BOOM!");
9.}
The answer is 10 (not 11) because even though the tmp variable is out of scope in line 8, the local variable still has a reference. When does the 11th variable become eligible for GC? Is it when the method ends?
------------------