It is always recommended to use the Dispose method to clean unmanaged resources. You should not implement the Finalize method until it is extremely necessary. At runtime C#, C++ destructors are automatically converted to Finalize method.
.NET Garbage collector does almost all clean-up activity for your objects. However, unmanaged resources (For example, Windows API-created objects, files, Database connection objects, COM objects, etc) are outside the scope of the .NET framework we have to explicitly clean our resources. For these types of objects, the .NET framework provides Object.Finalize method, which can be overridden and clean up code for unmanaged resources, can be put in this section.
The problem with finalizing is that garbage collection has to make two rounds in order to remove objects that have finalize methods.
For example, let's say there are three objects: Object1, Object2, and Object3. Object2 has the finalize method overridden and the remaining objects do not have the finalize method overridden.
Now, when a garbage collector runs for the first time, it searches for objects whose memory has to be free. He can see three objects but only cleans the memory for Object1 and Object3. Object2 it pushes to the finalization queue.
Now the garbage collector runs for the second time. The garbage collector gets to know there are no objects to be released and then checks for the finalization queue, and at this moment, it clears object2 from the memory.
So, if you notice that object2 was released from memory in the second round and not the first, that is why the best practice is not to write clean up Non .NET resources in the Finalize method but rather use the DISPOSE.
Dispose method belongs to the ‘IDisposable’ interface. We had seen in the previous section how bad it can be to override the finalized method for writing the cleaning of unmanaged resources. So if any object wants to release its unmanaged code, the best is to implement IDisposable and override the Dispose method of the IDisposable interface. Now, once your class has exposed the Dispose method it is the responsibility of the client to call the Dispose method to do the cleanup.
Use of Dispose Method
To use or override the dispose method, implement the IDisposable interface in your class, which comes under the System namespace. The following example is a class that implements an IDisposable interface for cleaning objects of files.
public class DisposeExample : IDisposable
{
// Flag: Has Dispose already been called?
private bool disposed = false;
private FileStream filestream;
private StreamReader streamreader;
public string ReadFile()
{
try
{
filestream = new FileStream(Path.Combine(Environment.CurrentDirectory, "TextFile1.txt"), FileMode.Open, FileAccess.Read);
streamreader = new StreamReader(filestream);
return streamreader.ReadToEnd();
}
catch (Exception ex)
{
throw ex;
}
finally
{
streamreader.Close();
filestream.Close();
this.Dispose(true);
}
}
protected virtual void Dispose(bool disposing)
{
if (disposed) return;
if (disposing)
{
filestream.Dispose();
streamreader.Dispose();
}
// Free any unmanaged objects here.
disposed = true;
}
}

Summary
Hope you understand why we should prefer the dispose method.
Ozmen GokPosted Apr 26, 2019, 1:53 PM
Good article, but not right:) You must not rely on solely dispose method. Some customer of our classes may not call dispose method of our class. In this case for unmanaged codes, finalize methods must be overrriden. (~ destructor) Other case, memory leak would happen. To assure that our object is cleanded up from memory and free unmanaged resources that object using, we have to override finalize. You are true to best practise, we should call Dispose method instead of Finalize. But It does not mean " if we don't override finalize method for object that use unmanaged resources(In fact we cant define finalizer for object that use managed resources) , there will be no problem". Memory leak problem would happen.
SubashPosted Sep 29, 2016, 7:20 AM
Nice explanation thanks kailash
Former memberPosted Nov 3, 2015, 11:19 PM
yes client need to call dispose method, here i have override the dispose method to explicitly release object and implemented the Dispose method of IDispose interface for client calling,
Pravin KolhePosted Nov 3, 2015, 4:02 AM
Very nice article. I have a question like what exact message did below sentence convey? " it is the responsibility of the client to call the Dispose method to do the cleanup". Can't we set auto call to Dispose method? Also as I see, we have to explicitly mention the unmanaged objects to be disposed?
Former memberPosted Nov 1, 2015, 11:28 PM
Thanks Harshad
Harshad PansuriyaPosted Nov 1, 2015, 10:59 PM
Nice one