Consider a simple class A
below :
class A
{
public static int b = 10;
}
{
var objA = new A();
A.b = 30;
Console.WriteLine("Before GC Collect!");
Console.WriteLine(A.b);
objA = null;
GC.Collect(); //A is GC Collected
var objB = new A();
Console.WriteLine("After GC Collect!");
Console.WriteLine(A.b);
}
Note: The member b
is static
I expected an answer of 30 before GC collection
and 10 after GC Collection
When a object is GC Collected
, does it mean that all the static instances associated with that class are not destroyed ?
Why so ? Any ideas ?