What is the difference between Finalize and Dispose(Garbage collection)?
By in OOP/OOD on Aug 03 2006
  • Renu Agarwal
    Aug, 2016 12

    Finalize is implemented by declaring destructors in the class and garbage collector calls finalize on its own. We cannot call finalize explicitly. Dispose method marks an object for getting disposed off by garbage collector. We can call Dispose() explicitly on objects that we want to be garbage collected.

    • 0
  • Ravi Kumar
    Nov, 2006 14

    Class instances often encapsulate control over resources that are not managed by the runtime, such as window handles ,database connections, and so on. Therefore, you should provide both an explicit and an implicit way to free those resources. Provide implicit control by implementing the protected Finalize Method on an object (destructor syntax in C# and the Managed Extensions for C++). The garbage collector calls this method at some point after there are no longer any valid references to the object.


    In some cases, you might want to provide programmers using an object with the ability to explicitly release these external resources before the garbage collector frees the object. If an external resource is scarce or expensive, better performance can be achieved if the programmer explicitly releases resources when they are no longer being used. To provide explicit control, implement the Dispose method provided by the IDisposable Interface. The consumer of the object 

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS