17Managed and Unmanaged Memory
MEMORY
Variables are stored on the stack. The data it references can be on the stack (structs) or on the heap (classes). Structs also can be boxed, so objects on the heap are created. The garbage collector needs to free up unmanaged objects that are no longer needed from the managed heap. Using native APIs, memory can be allocated on the native heap. The garbage collector is not responsible for memory allocated on the native heap. You have to free this memory on your own. There’s a lot to consider with regard to memory.
When you use a managed environment, you can easily be misled to not pay attention to memory management because the garbage collector (GC) deals with that anyway. A lot of work is done by the GC; it’s very ...
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