When does garbage collection happen to static members?

  • Thread starter Thread starter Adam Smith
  • Start date Start date
A

Adam Smith

Hi. I have a static arraylist in a class which is populated during
the class's static constructor.

Will this arraylist or the class objects allocated on it ever be
garbage collected if I don't access it for a few hours? Other posts
to this board seem to point to no.

Thanks in advance.

Adam Smith
 
Yes. My arraylist is static, but the objects within it are not. (But
they are allocated in the static constructor) Are they garbage
collected?

Thanks again.

Adam Smith
 
Only if they are individually null'ed, like:

myArrayList[10]=null;

(assuming the object myArrayList[10] points to has no other
references). GC will occur.

Austin Ehlers
 
Back
Top