• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Objects eligible for GC

 
Ranch Hand
Posts: 78
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Source: K&B Self Test Ch3 Q11




Please, I need clear explanation why only ONE object is eligible for GC?
 
Ranch Hand
Posts: 33
MyEclipse IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are created 4 objects ( using 'new' )

Two of them are of type Beta : b1,b2
Two of them are of type Alpha : a1,a2

Look here, a2 is not null, so you can access its members b1 and b2 ( those which were created above using new )
[a2.b1 is same as a1.b1, since class alpha's b1 is static ]

Now it is clear that, you can access a2,b1 and b2 but you cant access a1 and that is eligible for GC.


Try it with paper and pen digramatically,


 
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
see the image attached... its a bit hazy though.

X -> reference that have been nulled
boxes -> the objects

so the object originally referred by a1 can now not be reached, all others can be reached through a2.

Hope this helps.
jr.jpg
[Thumbnail for jr.jpg]
 
Kamil Wojcik
Ranch Hand
Posts: 78
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Aakash,
Thank You for that pic, it's really helpful. Now it's clear!
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic