Click here to Skip to main content
Sign Up to vote bad
good
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:44


3 solutions

  Permalink  
Comments
Manas Bhardwaj - 3 Sep '12 - 6:07
yup +5
ridoy - 3 Sep '12 - 10:07
thanks Manas
As usual you should be reading the documentation and doing your own research.
Finalize[^]
Dispose[^]
  Permalink  
Comments
Manas Bhardwaj - 3 Sep '12 - 6:07
Good links +5
Wes Aday - 3 Sep '12 - 7:05
Thanks
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 - 3 Sep '12 - 2:20
5+
Prasad_Kulkarni - 3 Sep '12 - 2:33
Thank you Mohamed!
Manas Bhardwaj - 3 Sep '12 - 6:07
very well +5
Prasad_Kulkarni - 3 Sep '12 - 6:12
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
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 368
1 OriginalGriff 261
2 Mayur_Panchal 153
3 Mohammed Hameed 145
4 Dave Kreskowiak 125
0 Sergey Alexandrovich Kryukov 8,146
1 OriginalGriff 6,236
2 CPallini 3,482
3 Rohan Leuva 2,703
4 Maciej Los 2,234


Advertise | Privacy | Mobile
Web02 | 2.6.130516.1 | Last Updated 3 Sep 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid