• 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

Q from Dan's Garbage Collection

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Guys/Gals
Which objects are eligible for garbage collection after method m1 returns?
class I {
private I other;
public void other(I i) {other = i;}
}
class J {
private void m1() {
I i1 = new I();
I i2 = new I();
I i3 = new I();
i1.other(i3);
i2.other(i1);
i3.other(i2);
}
public static void main (String[] args) {
new J().m1();
}
}

Dans answer is i1 i2 i3 ,however I think since all of the objects are being refered by other and non of these are not isolated islands of references ,non is eligible
Any comments?
 
Mandeep Sethi
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
GOT IT
 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mandeep,
I am confused too can you explain why it is so?
Thanks in advance
 
Ranch Hand
Posts: 443
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Sudhakar Krishnamurthy:
Mandeep,
I am confused too can you explain why it is so?
Thanks in advance


This is a form of circular reference. i1 has a reference to i3, i3 has a reference to i2, and i2 has a reference to i1. However, outside of that, there are no reference to any of these objects. So they are all eligible for garbage collection.
 
Mandeep Sethi
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ditto , i thought the same
 
reply
    Bookmark Topic Watch Topic
  • New Topic