Summary
This chapter focused on the way the runtime (through the garbage collector) manages the lifetime of objects and resources. We learned how the garbage collector works and how to write finalizers to dispose of native resources. We have seen how to properly implement patterns for the deterministic release of objects with the IDisposable
interface and using
statements. We also looked at Platform Invocation Services, which enable us to make native calls from managed code, as well as writing unsafe code—which is code that the CLR cannot verify for safety.
In the next chapter of this book, we will look at a different programming paradigm, functional programming, and see what its key concepts are in C# and what they enable us to do.