Chapter 4: Memory Management
In this chapter, we will be looking at object generations and how to avoid memory issues, followed by a discussion on strong and weak references. Then, we will look at finalization and how we can suppress finalization by implementing the IDisposable
pattern to clean up managed and unmanaged resources. Finally, we will take a high-level look at ways to avoid memory leaks.
In this chapter, we will be covering the following topics:
- Object generations and avoiding memory issues: In this section, we learn about object generations and
System.OutOfMemoryException
. We learn how to predict out-of-memory errors before they happen by using theSystem.Runtime.MemoryFailPoint
class. - Understanding long and short weak references: In this section, we learn about long and short weak references and how they are affected by the garbage collector.
- Finalization: In this section, we look at how to use finalizers to clean up resources, and understand why we...