After the end of a block
{
}
What happens to the variable that are in the block?
{
int a;
a=2;
int b = 3;
}
//What happened now???
and what happen after this block
{
int a=2;
int b = 3;
}
GC.Collect();
Is it clear?
If the tags I have selected is wrong please edit it or if you can edit my question to be clear please edit it.
At the end of a block, all variables declared inside just ‘go out of scope’.
Most likely they are popped of the stack but the details are op to the optimizer(s).
And since your example variables are all
ints (ValueTypes) they have nothing to do with Garbage Collection.If we change the last example to:
Then the memory for the StringBuilder will be collected in GC.Collect(). Note that a normal program never needs to call GC.Collect().