Click here to Skip to main content
11,577,522 members (23,415 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: .NET4
what is finalize and dispose method in .net(C#) and what is the use and where we use
Posted 2-Sep-12 15:44pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

  Permalink  
Comments
Manas Bhardwaj at 3-Sep-12 6:07am
   
yup +5
ridoy at 3-Sep-12 10:07am
   
thanks Manas
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

As usual you should be reading the documentation and doing your own research.
Finalize[^]
Dispose[^]
  Permalink  
Comments
Manas Bhardwaj at 3-Sep-12 6:07am
   
Good links +5
Wes Aday at 3-Sep-12 7:05am
   
Thanks
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Finalize()
1.This is the C# equivalent of destructor ~Object() syntax in C#.
In VB.Net you implement the Finalize() by overriding it. But, in C# the compiler translates the destructor to a Finalize() method.
2. Finalize() can NOT be overridden or called in C#.
3. Since, Finalize() is called by the Garbage Collector, it is non-deterministic.

Dispose()
1. This has to be implemented in classes implementing IDispose interface.
2. Its the right place for freeing-up unmanaged resources like file, handles, and connections etc.
3. Dispose() method is called explicitely in the code itself.
4. Dispose() method is automatically called (for objects which implement IDispose), when used in a "using" statement.
From: here[^]

Refer more detailed description with example on MSDN: Finalize and Dispose[^]

Difference:
Dispose Vs Finalize[^]
Finalize() and Dispose() methods in .Net?[^]
  Permalink  
Comments
Mohamed Mitwalli at 3-Sep-12 2:20am
   
5+
Prasad_Kulkarni at 3-Sep-12 2:33am
   
Thank you Mohamed!
Manas Bhardwaj at 3-Sep-12 6:07am
   
very well +5
Prasad_Kulkarni at 3-Sep-12 6:12am
   
Thank you Manas!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 DamithSL 180
1 OriginalGriff 115
2 Richard MacCutchan 100
3 Abhinav S 90
4 Peter Leow 80
0 OriginalGriff 820
1 Sergey Alexandrovich Kryukov 681
2 Abhinav S 528
3 F-ES Sitecore 420
4 Suvendu Shekhar Giri 375


Advertise | Privacy | Mobile
Web03 | 2.8.150603.1 | Last Updated 3 Sep 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100