• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Garbage Collection

 
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Q12.
1.public void count(){
2.for(int i=1;i<10;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 the System.out object is not keeping a reference)
(a)None
(b)1
(c)8
(d)9
The answer mentioned is (c).Should'nt it be (d) because,8 objects are eligible for garbage collection when control is within the for loop scope.Once control moves out of the for block scope,the reference to the ninth object is lost thus,making the last String object(ninth object)too eligiible for garbage collection.
Pls let me know ur opinion.
Thanks.
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are right. Also just have a search with the word "BOOM" and you will get a lot of explanations for the answer
 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey !
U can look up "BOOM" in the search and get to a lot of such
code. In addition to this, Please LOOK at the Question, if
there is any code like System.gc() or not, and then at what
point in the code you are talking abt the objects etc etc
Praveen Zala
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic