• 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

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is the question from K&B book page 275


How many objects are eligible for GC?

In my opinion,
Object refered by a2 is accessible
Object refered by b2 is accessible via a2.b2
Object refered by a1 is not accessible

What about Object refered by b1???

Please reply. Thank you.

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Object referred by b1 is accessable through a2.b1 since b1 is a static variable.

a1.b1 = b1; this statement makes the static b1 referance to refer the object referred by b1 in the main method. So it automaticly says that a2.b1 = b1; too.
 
Peter Swiss
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh yes, static variable is associated with the class! Cool.

Thanks!
 
Ranch Hand
Posts: 50
Android Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So the answer is one, just the object referred by a1 is GCable.
 
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think the answer is 2.
Objects referenced by a1 & b2.
 
John Schubert
Ranch Hand
Posts: 50
Android Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I think the answer is 2.
Objects referenced by a1 & b2.



No, only a1 is GCable. The object referenced by b2 is also referenced by the Alpha a2.
 
Ram Reddy
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My bad.
you are correct John...
 
reply
    Bookmark Topic Watch Topic
  • New Topic