---
title: "What is the difference between Finalize() and Dispose()?"  
description: "What is the difference between Finalize() and Dispose()?"  
author: "John William"  
published: 2010-11-11  
updated: 2013-05-27  
canonical: https://www.mindstick.com/forum/101/what-is-the-difference-between-finalize-and-dispose  
category: "c#"  
tags: ["c#"]  
reading_time: 3 minutes  

---

# What is the difference between Finalize() and Dispose()?

[Please Explain](https://www.mindstick.com/forum/344/hi-rohith-i-am-new-for-mvc-please-explain-how-to-set-implicitly-isauthenticated-true)

## Replies

### Reply by yang welar

## Finalize()

The Garbage Collector calls this method at some point after there are no longer valid references to that object in memory.

The framework does not guarantee that when this will happen, you can force for Garbage Collection but it will hurt performance of your program. Finalize() belongs to the Object class and it will be called by the runtime.

## Dispose()

There are some resources like windows handles, database connections , network connections, files, etc. which cannot be collected by the Garbage Collector. If you want to explicitly release some specific objects then this is the best to implement IDisposable and override the Dispose() method of IDisposable interface.

source:

http://net-informations.com/faq/framework/finalize-dispose.htm

yang.

### Reply by Lakshmi Narayanan

Hi,\
refer this link\
http://www.geekinterview.com/question_details/37506

### Reply by Anonymous User

**Design Pattern :** If your classes use unmanaged resources, you need to implement both Dispose & Finalize. Dispose() is\
called by user code, that is, the code that is using your class.\
Finalize/Destructor cannot be called by User code, it's called by Garbage\
Collector\
**Finalize :** Is a destructor, called by Garbage Collector when the object goes\
out of scope. Implement it when you have unmanaged resources in your code, and\
want to make sure that these resources are freed when the Garbage collection\
happens.\
**Dispose :** Same purpose as finalize, to free unmanaged resources. However,\
implement this when you are writing a custom class, that will be used by other\
users. Overriding Dispose() provides a way for the user code to free the\
unmanaged objects in your custom class

### Reply by Amit Singh

**Difference between Finalize() and Dispose() method** \
**Finalize :** **\** 1.Finalize() is called by the runtime \
2.Is a destructor, called by Garbage Collector when the object goes out of scope. \
3.Implement it when you have unmanaged resources in your code, and want to make sure that these resources are freed when the Garbage collection happens.\
\
**Dispose :** **\** 1.Dispose() is called by the user\
2.Same purpose as finalize, to free unmanaged resources. However, implement this when you are writing a custom class, that will be used by other users. \
3.Overriding Dispose() provides a way for the user code to free the unmanaged objects in your custom class.\

Dispose() method permanently removes connection object from memory and the resource no longer exists for any further processing.

\


---

Original Source: https://www.mindstick.com/forum/101/what-is-the-difference-between-finalize-and-dispose

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
