Summary

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. We learned about the performance implications of using the Finalize method, and then we went on to understand how the IDisposable interface helps overcome its shortcomings. We learned about how we implement the IDisposable interface in a class and how we can combine both the Dispose and Finalize methods to improve the performance of the system. Finally, we learned about using the using block for classes that implement the IDisposable interface.

In the next chapter, we will look at how reflection works in C#. 

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.128.145