Wednesday, March 30, 2016

What is difference between Dispose and finalize method in c#?



Dispose Method ()

-          Dispose method belong to the IDisposable interface

-          Dispose method will be used to free unmanaged resource like files, database connections etc.

-          To clear unmanaged resource we have to manually write the code to implement it.

-          It is faster method

-          Syntax of this method is void Dispose()


Finalize Method ()

-          Finalize method belong to the object class.

-          It is automatically raised by garbage collection mechanism when the object goes to scope.

-          It is slower method

-          Syntax for this method is protected virtual void Finalize()


  


No comments:

Post a Comment