Friday 4 November 2016

Dispose Vs Finalize Methods

Dispose() Method

1. Dispose method is used to free unmanaged resources like files, data base      connections etc.

Now the question here is What is unmanaged resources

Here is the Answer ===>

The term "unmanaged resource" is usually used to describe something not directly under the control of the garbage collector. For example, if you open a connection to a database server this will use resources on the server (for maintaining the connection) and possibly other non-.net resources on the client machine, if the provider isn't written entirely in managed code.

2. To clear unmanaged resources we need to write a code manually to raise a Dispose() method.


3. Dispose() method belongs to IDisposable interface.

4. If we need to implement this method for any custom classes we need to inherit from IDisposable interface.



Finalize() Method

Finalize() method is also used to free unmanaged resources like files, data base connections etc.

It is automatically raised by Garbage Collection Mechanism whenever object goes out of scope.

Finalize() method belongs to Object class






Hope this information  helpful to you. Thank you for taking time to look at my blog. ----- Syed Sadiq Ali.      






No comments: