The last major topic we'll cover in this chapter is memory allocation and deallocation. The material we cover in this section gets relatively complex and you won't need to know it right away, so feel free to revisit this section later if you'd rather get a stronger handle on the basics first.
C# is a garbage-collected language, which means the actual process of allocation and deallocation is done by a garbage collector automatically according to an algorithm, but there are ways to manage your data to make sure you avoid common memory issues (even in a garbage-collected language) and keep everything optimized.
To understand optimization of memory, first you have to understand the different types: stack memory and heap memory.
Imagine stack memory as a neatly organized stack of books you're going to read. You set the order, but you need to read through the books on top before you can access the books in the middle.
Heap memory, by contrast...