Heap Versus Stack
Lots of books start the discussion about reference types versus value types by pointing out their different memory-allocation characteristics. To say the least, this is a weird thing to do because this is truly an implementation detail. So the first decision factor when choosing between a reference type and a value type should concentrate on the intended semantics as opposed to potential benefits in terms of memory-allocation and -deallocation patterns.
We should pay some attention to the way things work on this level, too. Here’s the deal:
• Value types (such as structs) are stack allocated.
• Reference types (such as classes) are heap allocated.
I’m actually omitting a slight detail for now (boxing), but this is the general ...
Get C# 4.0 Unleashed now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.