1.

What Is The Difference Between “dispose” And “finalize” Variables In C#?

Answer»

Dispose() Method

  • Dispose method will be used to free unmanaged RESOURCES like files, database connection etc.
  • To clear unmanaged resources we NEED to write code manually to raise dispose() method.
  • This Dispose() method BELONGS to IDisposable interface.
  • If we need to implement this method for any custom classes we need to inherit the class from IDisposable interface.

 Finalize() Method

  • Finalize method also free unmanaged resources like database connections, files etc.
  • It is automatically raised by garbage COLLECTION mechanism whenever the object goes out of scope.
  • This method belongs to object class.
  • We need to implement this method whenever we have unmanaged resources in our code and make sure these resources will be freed when garbage collection process done.

Dispose() Method

 Finalize() Method



Discussion

No Comment Found