---
title: "What is the difference between dispose() and finalize()?"  
description: "What is the difference between dispose() and finalize()?"  
author: "Apollonia Nealey"  
published: 2017-11-15  
canonical: https://answers.mindstick.com/qa/30675/what-is-the-difference-between-dispose-and-finalize  
category: "programming"  
reading_time: 2 minutes  

---

# What is the difference between dispose() and finalize()?

What is the [difference](https://www.mindstick.com/blog/398/difference-between-object-type-and-var-type) between dispose() and [finalize](https://www.mindstick.com/interview/686/what-is-the-significance-of-the-finalize-method)()?

## Answers

### Answer by Arti Mishra

**The difference between dispose() and finalize():** Generally finalize() and dispose() method is used for **releasing the unmanaged resources** like files, database connections, etc. But the main difference is that dispose() method is **invoked(called) by the user** and finalize( ) method is **invoked(called) by the garbage collector before the object is destroyed**. dispose( ) method is declared as public, but finalize( ) method is declared as private and at the runtime when the destructor is called it automatically Converted to Finalize method . **\****Example of dispose() method** **\**public class Test : IDisposable { private bool disposed = false; // dispose method declare public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } protected virtual void Dispose(bool disposing) { if (!disposed) { if (disposing) { // clean the managed objects } // clean the unmanaged objects disposed = true; } } } **Example of finalize() method** \
public class Test : IDisposable { private bool disposed = false; //Implement IDisposable. public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } protected virtual void Dispose(bool disposing) { if (!disposed) { if (disposing) { // clean the managed objects } // clean the unmanaged objects disposed = true; } } //At runtime C# destructor is automatically Converted to Finalize method ~Test() { Dispose(false); } } \


---

Original Source: https://answers.mindstick.com/qa/30675/what-is-the-difference-between-dispose-and-finalize

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
