If one defines an anonymous delegate, say, inside a function that uses a local variable of that function but the anonymous method can be called outside the function(say it is added to a list) then how is the local variable used by the anonymous delegate?
A test shows that the variable does have the correct value which I assume is because it is not GC'ed. It also showed that the variable has the last value(right before the function call ended rather than the before(which is generally how you think about it)).
This seems highly error prone but I guess is acceptable.
But how is the stack itself for the function defined? Is the function not GC'ed either?
It seems one has to be extremely careful when using non-local variables inside the definition of an anonymous function. As far as I can tell it is useless to do so(Since it is outside the scope of the function) and an error warning show be thrown?
(Note I am not talking about calling an anonymous function but defining it)
View Complete Post