Garbage Collection misunderstanding in c#
i have searched on google not getting what i want. i don't know i am right
or wrong. look , i have trying to understand GC.Collect() so here is the
code..
public class class1
{
public static int Count;
public class1(int j)
{
int i = j;
}
~class1()
{
SomeSubscriber.Count++;
}
}
i have run this code in my main method..
for (int i = 0; i < 10; i++)
{
class1 subscriber = new class1(i);
subscriber = null;
}
GC.Collect();
GC.WaitForPendingFinalizers();
Debug.WriteLine(class1.Count.ToString());
i am getting output 0 but it should bebe 10 according to me because
GC.Collect() must have remove class1 objects from memory so class1
destructor must be called so the count must be increased to 10..can any
body explain this..
No comments:
Post a Comment