aspose file tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes doubt regarding garbage collection Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "doubt regarding garbage collection" Watch "doubt regarding garbage collection" New topic
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 >...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: doubt regarding garbage collection
 
Similar Threads
How many objects are Garbage collected.Explain
One more question on garbage collection
GC Question from Exam Cram Page 163
Garbage collection question from J@Whiz1.4
Variables out of scope eligible for garbage collection