.NET automatiškai valdo atmintį naudodamas šiukšlių surinkiklį (GC) — jis išdėsto objektus valdomoje krupoje ir atgauna tuos, kurie nėra pasiekiami, todėl jūs neturite rankiniu būdu atlaisvinti atminties. Supratimas apie GC (generacijinį, stack/heap padalijimą ir IDisposable) yra svarbus dėl našumo ir korektiškai.
Stack ir 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.
