This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Garbage collection and refrences

 
Miles Green
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Question 13 of chap 17 of K&B is:
Which statement is true?
...
C. If an object can be accessed from a live thread, it can't be garbage collected.
... (other answers not relevant)
The answer is obviously C... but is that statement actually true?
The book explains breifly strong, soft, weak, and phantom refrences, saying that only strong refrences are not garbage collected at some point, but if you have a weak refrence to an object, you have access to the object, but it can be garbage collected, proving the true statement false.
Is my logic correct? (I know this is not on the exam, but you cant say the statement is true if it isn't)
 
fethi makhlouf
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Green,
I think you are right! but here they try to say , implicitly, that object is strongly referenced, may be Kate and Bert have more!
 
Sanjay Gandham
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Miles,
Here is my take on it. The book states that unless told explicitly otherwise, accessibility and/or refrence usually refer(s) to strong references. As objects with strong references cannot be collected, the answer is correct. The book also states that you do not need to know the advanced management model for the exam, so at least in the context of the exam, the question and answer are correct.
 
Corey McGlone
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Sanjay Gandham:
The book also states that you do not need to know the advanced management model for the exam...

Exactly. Although there is a model for advanced reference control, you need not know it for the SCJP exam. Within the context of the exam, you can assume that any reference is a "strong" reference.
Corey
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic