.NET خودکار طور پر میموری کو گاربج کلیکٹر (GC) کے ذریعے منظم کرتا ہے — یہ managed heap پر آبجیکٹس allocate کرتا ہے اور وہ جو reachable نہیں رہتے ان کو reclaim کرتا ہے، تو آپ کو manually میموری free کرنی نہیں پڑتی۔ GC کو سمجھنا (generational، stack/heap کی تقسیم، اور IDisposable) کارکردگی اور صحیح کام کے لیے اہم ہے۔
Stack بمقابلہ 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.
