Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

When are inner class objects garbage collected

 
Deepti Sabarinath
Greenhorn
Posts: 7
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
I have a question.
Will an inner class object be garbage collected before the outer class object ?
a) in the case of static nested classes
b) in the case of nonstatic inner classes
Thanks
Deepti
 
Pradeep bhatt
Ranch Hand
Posts: 8927
Firefox Browser Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the inner goes out of scope inner class will be gc 'ed. If the outer class goes out of scope it will be garbage collected.
 
Vad Fogel
Ranch Hand
Posts: 504
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Inner class objects are no different from any other object on the heap: an object becomes available to GC when no live thread can access it through the object reference.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic