I am sorry if "Safe" is a missleading word, I was not sure what word to use in this situation. I was wondering if for instance using
public static List<myObj> myList = new List<myObj>();
is acceptable in C#. Static variables stick around in the RAM throughout the life cycle of the application no matter what, so for instance in applications such as ASPX, this can lead to some unwanted behavior and the GC will not collect the allocations.
I have noticed that if I have a list of objects, which is static, in say a static "global" class ie.
globl.myList.add(foo);
then they stay throughout the life of the application. Does this mean that if I have a static list of objects, then the objects themselves which are appended to the list are static themselves, or is it because there is a reference to them, the GC does not collect them? In other words, if I remove an element, will the GC collect it later or is it going to be stuck in the heap until the application dies?
Thanks ahead of time!