From IT Skills
Jump to: navigation, search

A: managed application does not free memory if variable is used in runtime by some thread

let's see example

var a = 0;

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]

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?

A: yes

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


Dispose is NOT automatically called and must be explicity called... The Garbage collecter will never directly execute a Dispose method for you. The GC will execute finalizers when it feels like it.