Monday 20 April 2015

Difference between Finalize and Dispose



                  Finalize
                  Dispose
1- Finalize () belongs to the Object class.
1-Dispose() belongs to the IDisposable interface
2-It is automatically called by the Garbage Collection mechanism when the object goes out of the scope.
2-We have to manually write the code to implement it(User Code)
3-It is slower method and not suitable for instant disposing of the objects.
3-Faster method for instant disposal of the objects.
4-It is non-deterministic function
4-It is deterministic function as Dispose() method is explicitly called by the User Code
5- It claiming unused managed objects.
5:- It claim unused unmanaged  objects.
Ex :-  file handling, connections etc.

No comments:

Post a Comment