.NET gestisce la memoria automaticamente tramite un garbage collector (GC) — alloca gli oggetti sull'heap gestito e recupera quelli non più raggiungibili, quindi non devi liberare manualmente la memoria. Comprendere il GC (generazionale, la divisione stack/heap e IDisposable) è importante per le prestazioni e la correttezza.
Perché è importante
Stack → value types (locals), method frames; fast, automatically freed when scope ends.
Heap → reference type objects (class instances); managed by the GC.
A reference variable lives on the stack but points to its object on the heap.
