wood burning stoves*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes When are inner class objects garbage collected Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "When are inner class objects garbage collected" Watch "When are inner class objects garbage collected" New topic
Author

When are inner class objects garbage collected

Deepti Sabarinath
Greenhorn

Joined: Oct 06, 2003
Posts: 7
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

Joined: Feb 27, 2002
Posts: 8919

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.


Groovy
Vad Fogel
Ranch Hand

Joined: Aug 25, 2003
Posts: 504
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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: When are inner class objects garbage collected