A: managed application does not free memory if variable is used in runtime by some thread
let's see example
var a = 0; a++; Thread.Sleep(10000);
when memory for variable a will become free?
it is freed when variable a is gone from scope of executing thread, in other words if thread executes the place where a has no meaning
so local variable are freed very soon
static variables[edit | edit source]
but static variables are not freed at all because executing thread can see it always, static variables have global scope, they will persist for the duration of AppDomain.
B: so static variables are never freed?
static variable may become dangerous if it is ARRAY or LIST,
CACHES are implemented as such statics variables most often
that is why program managers are afraid of caches