Here is a method, which creates a number of
String objects in the course of printing a count down sequence.
1. public void countDown() {
2. for( int i = 10 ; i >= 0 ; i-- ){
3. String tmp = Integer.toString( i );
4. System.out.println( tmp );
5. }
6. System.out.println("BOOM!");
7. }
When the program reaches line 6, how many of the String objects created in line 3 are eligible for garbage collection? Assume that the System.out object is not keeping a reference.
The solution is none , but shudn't it be 9.
Everytime a new string object is assigned to temp and the previous one is dereferenced ?
TIA
Megha