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 Collection :exam lab

 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,


Could some explain me how the answer is Line 10.


Q: After which line only one object is eligible for GC


Here is my derivation

Situation at Line 9



at Line 10



so my answer was Line 11


how is it Line 10
Source :Exam Lab

 
Ranch Hand
Posts: 2066
IntelliJ IDE Clojure Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From where the object a4 came?
 
author
Posts: 23877
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Sudhakar Duraiswamy wrote:
how is it Line 10
Source :Exam Lab



After line 10 is executed, how do you reach the object that was created on line 4?

Henry
 
Sudhakar Duraiswamy
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Abimaran a4 is the object that was newly created at line 7 . I gave it a name a4 for reference.

@henry:
I didnt understand .Could you please elaborate your question





 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
IntelliJ IDE Clojure Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Sudhakar Duraiswamy wrote:@Abimaran a4 is the object that was newly created at line 7 . I gave it a name a4 for reference.

@henry:
I didnt understand .Could you please elaborate your question



Check this figure, I manage to draw it . In the line 10, the object, previously referred by a1, has no reference. So it's eligible for GC
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hiiiii sudhakar
i think for any object which is eligible for garbage collection the condition is that there should no refercence varible exist or by any way we cannot access that object.
in your question you can see after line 10 one object is eligible for gc.
thanks......have a good day.
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just to elaborate Ravi's point. Please note the object reference contained in a1 has already been copied to the other objects. Hence only a1 is eligible after line 10
 
"To do good, you actually have to do something." -- Yvon Chouinard
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic