.NET gestionează memoria automat printr-un colector de gunoi (GC) — alocă obiecte pe heap-ul gestionat și recuperează pe cele care nu mai sunt accesibile, deci nu trebuie să eliberezi manual memoria. Înțelegerea GC (generațională, împărțirea stack/heap și IDisposable) contează pentru performanță și corectitudine.
Stack vs heap
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.
