• 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
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

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: 23840
141
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
 
If tomatoes are a fruit, then ketchup must be a jam. Taste this tiny ad:
professionally read, modify and write PDF files from Java
https://products.aspose.com/pdf/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!