| Author |
doubt regarding garbage collection
|
shreya prabhu
Ranch Hand
Joined: Feb 10, 2007
Posts: 31
|
|
public void countDown(){ for(int i=0;i>=0;i--) { String tmp=Integer.toString(i);//line 5 System.out.println(tmp); } System.out.println("Boom");//line 8 } when program reaches line 8 how many objects created in line 5 are eligible for garbage collection? i thought it was 11 but the answer is 10 why? tmp is a local variable so it should be garbage collected isnt it?
|
 |
marc weber
Sheriff
Joined: Aug 31, 2004
Posts: 11343
|
|
Assuming you start at i=10 (rather than the typo i=0), I would say the answer is 11. Where did this question come from?
|
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
|
 |
shreya prabhu
Ranch Hand
Joined: Feb 10, 2007
Posts: 31
|
|
|
It is from whizlab mockexams practice exam 4
|
 |
shreya prabhu
Ranch Hand
Joined: Feb 10, 2007
Posts: 31
|
|
ya sorry i typed it wrong its for(i=10;i>=0;i--)
|
 |
Rodrigo Gomez
Greenhorn
Joined: Mar 09, 2007
Posts: 2
|
|
|
MMmmm, I think it is 11... because after line 8 all the objects (10 to 0, it means 11) lose the reference variable (also the last one, because it is declared inside the for loop)... only if you declare the reference variable outside the loop, then it'll be 11... or if you remove the >= and only put >...
|
 |
 |
|
|
subject: doubt regarding garbage collection
|
|
|