Wednesday, January 22, 2014

Dispose Vs Finalize method ?

Dispose:
1) Dispose is a method which used to handle resource cleanup in run time environments ,that uses automatic garbage collection

2) Dispose is available with those object which implements IDisposable interface. (Defaulty by framework)

3) Internally, it is called by Garbage Collector and cannot be called by user code.

Finalize:

1) Finalize is used to fire when the object is going to release the memory.We can set a alert message to says that this object is going to dispose

2) Explicitly, it is called by user code and the class implementing dispose method must implement IDisposable interface.

For Example,
If we are opening a file in our application,this will be released in Dispose() method.

Normally before releasing database connection, we have to close the database connection. we have to place the code for Closing the file operation will be taken place in Finalize() method..






No comments:

Post a Comment

Abstract Factory Vs Factory Method

Abstract Factory Provides an interface for creating families of related or dependent objects without specifying their concrete classes ...