13Managed and Unmanaged Memory
MEMORY
Variables are stored on the stack. The data they reference 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. When you use native APIs, you can allocate memory 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 into not paying attention to memory management because the garbage collector ...
Get Professional C# and .NET, 2021st Edition 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.