my understanding is that if you have an instance of a class that has members that occupy resources that you want released after you are done working with the instance of the class, then you can have the class implement the IDisposable interface and then inside the implemented Dispose() method you can perform any clean up necessary. When such an instance of a class is declared and initialized inside a "using" block, the runtime automatically calls the Dispose() method on the instance of the class after the "using" block goes out of scope. Often, the Dispose() method will contain a line such as "GC.SuppressFinalize(this)" which tells the GC not to call the destructor method (which implicitly calls System.Object.Finalize()) on the instance of the class after the instance of the class goes out of scope.
I don't understand exactly what the Finalize() or SupressFinalize methods do.
I mean I understand that if you have reference type variables pointing toward a null reference then the data in memory that the reference type variables initially pointed to become available for garbage collection, as long as no other reference types point toward that data. Calling GC.Collect() will call the destructor method on unreferenced objects in memory.
But I still don't get exactly what happens behind the scenes. In other words, if you have unreferenced objects in memory, then the next time the GC comes it will reclaim those memory resources allowing the occupied blocks of memory to be rewritten at a later time? And this reclaiming of memory resources happens the moment you call SuppressFinalize(this) or the moment the GC automatically calls the destructor method on unreferenced objects?
and having the SuppressFinalize(this) method call inside the Dispose() method means that every time the Dispose() method is called, the memory occupied by the object will automatically be reclaimed? in other words, is the effect of doing SuppressFinalize(this) the same as doing "obj = null; GC.Collect();" minus the decrease in performance caused by explicitly calling GC.Collect()?