This week's book giveaway is in the Agile forum.
We're giving away four copies of Fixing your Scrum and have Ryan Ripley & Todd Miller on-line!
See this thread for details.
Win a copy of Fixing your Scrum this week in the Agile forum!
  • 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
  • Paul Clapham
  • Rob Spoor
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Holloway
  • Piet Souris
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Himai Minh

SCJP 1.6 - Chapter 3 - Self Test - question 1

 
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Folks, This question was quoted before at this forum here. I have a doubt but I was not able to post a reply there so I am starting a new topic.

The question from the book, Chapter 3:


Q: when //do stuff is reached, how many objects are eligible for GC?
The answer for this as explained is: 2. Only one CardBoard object (c1) is eligible, but it has an associated short wrapper object that is also eligible.

My doubt: Why not C3? Afterall, it is getting a null from the go method during initialization, isn't it?

Thank you,

aditya
 
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
c3 isn't actually referring to any instance. Its just a reference variable with a value "null"

 
Aditya Kumar
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, so you mean, since c3 never referred to any object in it's lifetime, it was never ever eligible for Garbage collection?

If that is so, my doubt is clear.

thank you so much :-)

best,
a
 
Mohamed Sanaulla
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Exactly, by the time it returns from the go() method- c3 would have been assigned a null value.
 
author
Posts: 9031
21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't think you've quite got it yet!

You MUST know the difference between a reference variable and an object. And you MUST know that only objects can get garbage collected. Reference variables DO NOT get garbage collected.

hth,

Bert
 
Mohamed Sanaulla
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And for this I would recommend glancing through Head First Java or even K & B guide has got a nice explanation for this
 
Getting married means "We're in love, so let's tell the police!" - and invite this tiny ad to the wedding:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic