What is difference between dispose and finalize?


Finalize

  • Used to free unmanaged resources like files, database connections, COM etc. held by an object before that object is destroyed.
  • Internally, it is called by Garbage Collector and cannot be called by user code.
  • It belongs to Object class.
  • There is performance costs associated with Finalize method.

Dispose

  • It is used to free unmanaged resources like files, database connections, COM etc. at any time.
  • Explicitly, it is called by user code and the class implementing dispose method must implement IDisposable interface.
  • It belongs to IDisposable interface.
  • There is no performance costs associated with Dispose method.