• 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
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

Garbage Collection

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to figure out the answer. Really appreciate if someone can help.  The question is "How many objects are eligible for garbage collection once //do stuff is reached ?"  The answer is one and it kept me ponder which one is that.  


 
Rancher
Posts: 988
23
Netbeans IDE Oracle MySQL Database Tomcat Server C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
a1 is set to null, what that does is: the variable a1 referenced an object that was created and is now released--no references to it.  That object that a1 used to reference is now an orphaned object, no references to it, and is now eligible for garbage collection.

the object a2.b2 gets a reference to b2, it also has static reference a b1 object.  a2 is not set to null, so it retains it's references to its assigned objects.  the b1=null and b2=null only sets the variable reference b1 and b2 to null and does not affect the references in the a2 object. the object a2 remains in scope and referenced by a2 so it is not eligible for garbage collection.
 
Yik Siew Ngan
Greenhorn
Posts: 2
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for your answer.  I really appreciate it.
reply
    Bookmark Topic Watch Topic
  • New Topic