Finalize() and Dispose() methods in .Net?

Finalize and Destroy methods are cleanup methods in .Net.Both are ways to destroy the object. 

By object I mean when you have some unmanaged resources used in your class, you have to make sure that you write the logic to destroy them in the finalize() method. But this is the implicit way of destroying the unmanaged resources, as finalize is called by garbage collector when it find thats there is no reference to this object from the stack.There is an explicit way to destroy the unmanaged resources.That is by implementing IDisposable interface. By implementing this interface, ie you have to write the code to destroy the resource in Dispose() method, you can call the object to destroy itself whenever required in your code.



Ebook Download
View all
Learn
View all