Hi,
What is the main difference between Finalize() and Dispose()?
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
SenthilkumarRank #387 · 6.5K reputationPosted Mar 13, 2012, 9:45 PM EDT
The simply you can say the finalize is no guarantee to run and it happens implicitly.Where Dispose is explicitly called by the developers.
Satyapriya NayakRank #47 · 31.5K reputationPosted Mar 13, 2012, 9:50 PM EDT
Finalize and Dispose are both known as Finalizers.
They are the methods used to deallocate the memory of the objects
Differences:
FINALIZE
1)Finalize belongs to the Object class.
2)It is automatically called by the Garbage Collection mechanism when the object goes out of the scope(usually at the end of the program)
It is not called by the User Code.
In C#, suppose there is a class known as emp
class emp
{
//This is the destructor of emp class
~emp()
{
}
//This destructor is implicitly compiled to the Finalize method.
}
3)Not suitable for instant disposing of the objects.Sloer method.
DISPOSE
1)Dispose belongs to the IDisposable interface
2)we have to manually write the code to implement it(User Code)
ex: if we have emp class we have to inherit it from the IDisposable interface
and write code. We may have to suppress the Finalize method using GC.SuppressFinalize() method.
3)Faster method for instant disposal of the objects
Example: user interface Controls. Forms, SqlConnection class have built in implementaion of Dispose method.
Thanks