Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Garbage Collection :exam lab

 
Sudhakar Duraiswamy
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

 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From where the object a4 came?
 
Henry Wong
author
Marshal
Pie
Posts: 21003
77
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor 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
Clojure IntelliJ IDE 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
 
ravi keshri
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.
 
Faisal A Khan
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic