471,089 Members | 1,643 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,089 software developers and data experts.

When does garbage collection happen to static members?

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
Nov 15 '05 #1
3 1942
Adam, static objects are considered to be a part of the root of your
application and therefore not garbage collected.

For more information read "The Garbage Collection Algorithm" in :
http://msdn.microsoft.com/msdnmag/is...I/default.aspx

--
Greg Ewing [MVP]
http://www.citidc.com

"Adam Smith" <ad*********@hotmail.com> wrote in message
news:cd**************************@posting.google.c om...
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

Nov 15 '05 #2


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

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 15 '05 #3
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

On Sun, 07 Sep 2003 17:22:54 -0700, Adam Smith
<ad*********@hotmail.com> wrote:


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

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


Nov 15 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.