April 29, 2011

Dispose Vs Finalize

Dispose method is mainly controlled by the developer, and it frees all the resource upon the completion of the event. While Finalize method is controlled by the Garbage Collector(GC) and there is no predictability as to when the GC will call the finalize method to free the resources.


Finalize method cannot be overridden or called explicitly. It is basically used for implicit resource clean-up.


C# provides a USING statement , which ensures that Dispose() method will be called at the earliest possible time (Dispose method is automatically called if the class implements IDisposable and used in USING statement).



No comments:

Post a Comment

Your comments are valuable.