| Five main difference between Finalize and Dispose?
Below are the 5 main difference between Finalize and Dispose.
Finalize:-
(1)It is basically used to free unmanaged resources and example of these resources are Files, Database connections in application domain and many other resources. And these resources are held by an object before that object is destroyed.
(2)It is internal process and called by Garbage Collector automatically and we cannot called it manually by user code or by any other service.
(3)Finalize belongs to object class.
(4)This will implement when we have unmanaged resource in our code and we need to make sure that resource is freed when Garbage Collection happens.
(5)We will notice some effect on performance of website when garbage Collector is called and it will not suitable to free objects immediately.
Dispose:-
(1)Dispose is also used to free unmanaged resources that are not in use and example are Files and database connections in the application domain at any time.
(2)In dispose we will called it explicitly by manual user code.
(3)This Dispose() method belongs to IDisposable interface.
(4)If we need to implement this method for any custom classes we need to inherit the class from IDisposable interface.
(5)It will not show any effect on performance of website and we can use this method whenever we want to free objects immediately. | | |