C
Chuck Cobb
I am creating some static classes with static methods and static variables,
but I have a question: What is the lifetime of static classes and static
variables? Is there any risk that these items might be garbage collected
if they're not used for a period of time?
For example:
public static class test
{
static Collection<string> coll;
public static void AddItem()
{
coll = new Collection<string>();
coll.Add("abc");
}
public static string GetItem(int index)
{
return coll[index];
}
}
Suppose I call the AddItem method and nothing is holding a reference to this
class, what's to prevent it from being garbage collected and destroyed?
Do static members like this live for the life of the application without
being subject to garbage collection?
Thanks,
Chuck Cobb
but I have a question: What is the lifetime of static classes and static
variables? Is there any risk that these items might be garbage collected
if they're not used for a period of time?
For example:
public static class test
{
static Collection<string> coll;
public static void AddItem()
{
coll = new Collection<string>();
coll.Add("abc");
}
public static string GetItem(int index)
{
return coll[index];
}
}
Suppose I call the AddItem method and nothing is holding a reference to this
class, what's to prevent it from being garbage collected and destroyed?
Do static members like this live for the life of the application without
being subject to garbage collection?
Thanks,
Chuck Cobb