The finalize method, which we examined in the preceding section, has some performance implications for the system. With the Finalizer method, we are not sure of when the memory will be reclaimed by the garbage collector even after the object is no longer required. This implies that there is a possibility that unused memory will be persisted in a managed heap for longer than the desired amount of time.
With the IDisposable interface, we can assume control over when the memory is reclaimed for unmanaged resources in the application. The IDisposable interface in C# only has one method, which is Dispose().
In this method, we can perform the same cleanup of unmanaged resources that we did in the Finalizer method. The ...