In this chapter, we learned about memory management for unmanaged resources in C#. We revised the differences between managed code and unmanaged code in C#. We then looked at garbage collectors and delved into how they work. We learned about the memory storage structure of a managed heap, which it uses internally to allocate memory to different objects created during program execution. We learned about the internal divisions of generations, which the garbage collector uses internally to improve the performance of the system. We also learned about the mark-compact algorithm, which the garbage collector uses. We then explored how we can invoke garbage collection implicitly.
Following this, we went on to understand concepts about memory management for unmanaged objects. We learned about the Finalize method and how it facilitates memory management of an unmanaged object...