- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Difference Between dispose() and finalize() in C#
In this post, we will understand the difference between the methods ‘dispose’, and ‘finalize’ in C#.
Dispose
This method is defined in the IDisposable interface.
It has to be invoked by the user.
Whenever it is invoked, it helps free the unmanaged resources.
It can be implemented whenever a close() method is present.
It is declared as public method.
It is quick, and instantly disposes an object.
Since it performs instantaneously, it doesn’t affect performance.
Finalize
It is a method that is defined in the java.lang.object class.
It is invoked by the garbage collector.
It helps free the unmanaged resources just before the object is destroyed.
It is implemented to manage the unmanaged resources.
It is declared as private.
It is slower in comparison to the ‘dispose’ method.
Since it is slow, it affects the performance of the websites or applications.