1.

What are the differences between Dispose and Finalize?

Answer»
  • Dispose: - Dispose helps to RELEASE the object resources from the object and not access them again. It basically helps in external memory clean up.it uses the Dispose() method to free up all its expensive resources and making it for REUSE, and IDisposable interface is used which decides where and how Dispose() is used.
  • Finalize :- If Dispose is not CALLED then Finalize() method is called for the CLEANUP, when we don’t want to clean up the memory immediately and want to de-allocating the memory later we use Finalization. If Dispose does not CALL, then garbage collector uses the finalize() method.
DisposeFinalize
It is used to free unmanaged items like file or Database connectionIt can be used to free unmanaged items like files, database connections etc. held by an object before that object is destroyed
It belongs to IDisposable interfaceIt belongs to Object class
Called from user code and the class which is implementing dispose methodOnly called by Garbage Collector and not by user code


Discussion

No Comment Found