April 2018
Intermediate to advanced
300 pages
7h 41m
English
The Finalizer method is called by the GC, whereas the Dispose method has to be called by the developer explicitly in the program. The GC doesn't know if the class contains a Dispose method, and it needs to be called when the object is disposing to clean up the unmanaged resources. In this scenario, where we need to strictly clean up the resources rather than relying on the caller to call the Dispose method of the object, we should implement the Finalizer method.
The following is a modified example of the DatabaseManager class that implements the Finalizer method:
public class DataManager : IDisposable { private SqlConnection _connection; //Returns the list of users from database public DataTable GetUsers() { //Invoke ...