C# - Dispose vs Finalize


In this article we are going to discuss difference between Dispose and Finalize in C#. There are many blogs, articles are available on the internet regarding Dispose and Finalize but in this particular article I will try to explain to you with as much as simplest and realistic examples so you can get a clear idea of the Dispose and Finalize use in C#.

Difference Between Dispose and Finalize

S.No. Dispose Finalize
1 It is defined in the interface IDisposable interface. It is defined in java.lang.object class.
2 It is called explicitly by the developer It is called by the garbage collector
3It is provides deterministic cleanup of resources. Non-deterministic cleanup, timing is controlled by the garbage collector.
4No additional GC overhead. Incur additional performance cost due to GC needing extra cycles.
5It is part of the IDisposable interface, used for both managed and unmanaged resources. It is used primarily for unmanaged resources, provided by the object class.
6It can be used with a using statement for automatic resource management. Cannot be used with a using statement.

Prev Next