Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General 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
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

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: 3787
34
  • 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.
 
If you live in a cold climate and on the grid, incandescent light can use less energy than LED. Tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic