Understanding Memory Allocation
Chapter 4, “Data Types and Expressions,” discusses value types and reference types, describing how both of them are allocated in memory. Value types reside in the stack, whereas reference types are allocated on the managed heap. When you create a new instance of a reference type, via the New keyword, the .NET Framework reserves some memory in the managed heap for the new object instance. Understanding memory allocation is fundamental, but an important practice is to also release objects and resources when they are unused or unnecessary. This returns free memory and provides better performance. For value types, the problem has an easy solution: Being allocated on the stack, they are simply removed from memory when ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access