Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Kathy's Book- GC question

 
Ranch Hand
Posts: 203
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The following Q is from Kathy's book on SCJP1.4

After line 6 runs. how many objects are eligible for garbage collection?
A. 0
B. 1
C. 2
D. 3
E. 4
Answer given
10. B. By the time line 6 has run, the only object without a reference is the one generated
as a result of line 4. Remember that “Java is pass by value,” so the reference variable x is not
affected by the m1() method.

My answer is C. I completely agree with Kathy's answer and explanation given above. But what about the object created in the method m1()? Isn't that also eligible for GC as no thread can reach it?
I would like to hear from Kathy.
Thanks in advance,
Sarma
 
Ranch Hand
Posts: 366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

But what about the object created in the method m1()? Isn't that also eligible for GC as no thread can reach it?


Sarma,
Infact, thats the only object eligible for GC. According to the explanation, if you closely observe, the only object without a reference is the one generated. This object is generated in the m1() method and its reference is passed as a return reference variable to the line 4. Apart from this object , there is no new object being created at line 4
Hope this helps
Sri
 
Sarma Lolla
Ranch Hand
Posts: 203
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Sri. I missed that.
 
author
Posts: 9034
21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sri -
You beat us to the punch !
good job..
 
Sridhar Srikanthan
Ranch Hand
Posts: 366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bert,
Hope I can repeat the same performance in the final exam
Sri
 
If you're gonna buy things, buy this thing and I get a fat kickback:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic