This week's book giveaway is in the Artificial Intelligence and Machine Learning forum.
We're giving away four copies of Machine Learning with R: Expert techniques for predictive modeling and have Brett Lantz on-line!
See this thread for details.
Win a copy of Machine Learning with R: Expert techniques for predictive modeling this week in the Artificial Intelligence and Machine Learning 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

garbage collector Java SE 8 chapter 1 question 19

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, everyone. I am new in coderanch. Sorry me if this question has already been posted, I couldn't find the answer. I am preparing for OCA exam and in  chapter 1 there is a question about garbage collector:

Suppose we have a class named Rabbit. Which of the following statements are true?
(Choose all that apply)




A. The Rabbit object from line 3 is first eligible for garbage collection immediately
following line 6.
B. The Rabbit object from line 3 is first eligible for garbage collection immediately
following line 8.
C. The Rabbit object from line 3 is first eligible for garbage collection immediately
following line 12.
D. The Rabbit object from line 4 is first eligible for garbage collection immediately
following line 9.
E. The Rabbit object from line 4 is first eligible for garbage collection immediately
following line 11.
F. The Rabbit object from line 4 is first eligible for garbage collection immediately
following line 12.

The answer is B,D. The Rabbit object from line 3 has two references to it: one and three. The references
are nulled out on lines 6 and 8, respectively. Option B is correct because this
makes the object eligible for garbage collection after line 8
-----------------------------------------------------------------------------------------------------------

My question is, doesn't object from line 3 have 3 references to it: one, three and four?
Shouldn't object four be nulled in order for object one to be eligible for garbage collection?


-----------------------------------------------------------------------------------------------------------
 
Rancher
Posts: 3444
33
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Shouldn't object four be nulled


It is null because one was set to null on line 6 before four got the value from one.
 
Happily living in the valley of the dried frogs with a few tiny ads.
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!