C# is a managed language. Unlike other languages, such as C++, where we need to explicitly manage memory cleanup, in C# we do not need to worry about it. The garbage collector in the .NET Framework manages the allocation and release of memory for us.
The garbage collector ensures that, as long as we use managed types, that is, value and reference type variables, then we don't have to explicitly destroy an object in order to free its memory. However, as we discovered in Chapter 8, Creating and Using Types in C#, C# also gives us the freedom to utilize the capabilities of pointer object types in it. In C#, we must declare that code using the unsafe syntax. Apart from that, for variables declared in unsafe code, we also need to manage the release of memory.
In this chapter, as well as looking into memory management for unsafe code we will delve...