• 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

Regular inner classes & garbage collection

 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What happens, if an instance of an outer class becomes gc-eligible but there are instances of its inner class (in relation with this particular outer class instance) that are still referenced from stack or other objects? Is it possible at all?
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Think about it. To be GC eligible, an object can't be reachable. How do you propose that an object be GC eligible, if it is still reachable from an inner class object?

Henry
 
Dariusz Kordonski
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think the problem is that there are a lot of sources that define 'being reachable' as 'there is somewhere a reference variable that points to this object'. And this is the way I always thought of it. And since there may be no direct reference variable pointing to outer class within the inner class, according to such definition it could be possible for an outer class instance to be gc-eligible. But, of course, if we think of being reachable in general sense, it is always possible to reach outer class with 'OuterClass.this' from within inner class... are there any more cases when 'object is not reachable != 'there is no reference variable pointing to it' ?
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
An instance of an inner class has a reference to the outer class (available through OuterClass.this). So if the instance of the outer class is gc-eligible, then the inner class instance is gc-eligible by definition. If the inner class instance is not gc-eligible then neither is the outer class instance.
 
reply
    Bookmark Topic Watch Topic
  • New Topic