Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring 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
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

How many object are eligible for gc - problem

 
Ranch Hand
Posts: 101
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is excercise from "ExamLab for SCJP 6.0"
How many objects are eligible for the gc after executing statement "c.aob=null"

I made a graph and I can see only one object eligible for gc. The answer is 2. So can you show me where is my mistake?


 
Ranch Hand
Posts: 385
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Even i see only one object eligible for GC which was referred by c initially.
 
Sheriff
Posts: 9671
42
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A d = new A().aob =new A();
This is the key line here. There is one object eligible for GC here. The object in bold is actually assigned to d and the object in italics is eligible for GC...
 
Ranch Hand
Posts: 423
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here:

d points to the last object created with new A(), not the object created with new A().aob.
Object new A.aob is eligible to gc since there is no reference that points to it.
And the total number of objects eligible for gs is 2.

Look at this example.

 
Mark Moge
Ranch Hand
Posts: 101
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for clarifying. Now I can see how it works.
 
Ranch Hand
Posts: 774
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can smell in air, that why ExamLab is considered to be tough.

I must praise Devaka for putting such a great effort and making it open-source for the community.
My special thanks to Devaka.

Best Regards,
 
Sheriff
Posts: 6619
1253
IntelliJ IDE jQuery Eclipse IDE Postgres Database Tomcat Server Chrome Google App Engine
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Prithvi Sehgal wrote:... and making it open-source for the community.


Open-Source ???
 
Prithvi Sehgal
Ranch Hand
Posts: 774
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Apologies Devaka wrong word i must say. Not open-source.
To my knowledge, before somtime, ExamLab was free , i am not really sure if you have updated it at commercial level.
Let me know.

Best Regards,
 
Devaka Cooray
Sheriff
Posts: 6619
1253
IntelliJ IDE jQuery Eclipse IDE Postgres Database Tomcat Server Chrome Google App Engine
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Prithvi Sehgal wrote:i am not really sure if you have updated it at commercial level.


Nope, and never
 
    Bookmark Topic Watch Topic
  • New Topic