Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
How can we use in real time.
 
Can any one help me on this.
Posted 8-Mar-12 18:27pm
Comments
SAKryukov at 9-Mar-12 0:43am
   
Aha, real time... what do you mean by that?
--SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Nice article shares when and how to use finalize and dispose in .NET
 
Refer: http://www.devx.com/dotnet/Article/33167[^]
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

Please also see my comments to Solutions 1 and 2. You also need to understand how System.IDisposable.Disposed is used with the using statement (don't mix up with using clause):
 
http://msdn.microsoft.com/en-us/library/yh598w02%28v=vs.80%29.aspx[^].
 
For some use of System.IDisposable.Disposed beyond reclaiming of resources, please see my article: Hourglass Mouse Cursor Always Changes Back to its Original Image. How?[^].
 
—SA
  Permalink  
v2
Comments
member60 at 9-Mar-12 0:58am
   
agreed.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Finalize () is called by Garbage Collector implicitly to free unmanaged resources. The garbage collector calls this method at some point after there are no longer valid references to the object. There are some resources like windows handles, database connections which cannot be collected by the garbage collector. Therefore the programmer needs to call Dispose() method of IDisposable interface.
Dispose () of IDisposable interface is called by the programmer to explicitly release resources when they are no longer being used. Dispose () can be called even if other references to the object are alive.
 
For more detail with example, refer below link:
http://www.dotnetobject.com/expage.php?exurl=http://msdn.microsoft.com/en-us/library/b1yfkh5e%28VS.80%29.aspx[^]
  Permalink  
Comments
SAKryukov at 9-Mar-12 0:47am
   
Basically correct, I voted 4.
It is important to note, that IDisposable and IDisposable.Dispose formally is not related to any kind of clean up of any resources. This is just one of the typical uses of it. This is a formal construct used to chain some action or in "using" statement (don't mix it up with "using" clause).
--SA
SAKryukov at 9-Mar-12 0:50am
   
I added additional answer with a reference to MSDN help page an my short article, please see.
--SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

The finalizer method is called when your object is garbage collected and you have no guarantee when this will happen (you can force it, but it will hurt performance).
 
The Dispose method on the other hand is meant to be called by the code that created your class so that you can clean up and release any resources you have acquired (unmanaged data, database connections, file handles, etc) the moment the code is done with your object.
  Permalink  
Comments
SAKryukov at 9-Mar-12 0:48am
   
Basically correct, I voted 4. It is important to note, that IDisposable and IDisposable.Dispose formally is not related to any kind of clean up of any resources. This is just one of the typical uses of it. This is a formal construct used to chain some action or in "using" statement (don't mix it up with "using" clause).
--SA
SAKryukov at 9-Mar-12 0:52am
   
I added additional answer with a reference to MSDN help page an my short article, please see.
--SA

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

  Print Answers RSS
0 OriginalGriff 693
1 George Jonsson 370
2 BillWoodruff 317
3 Sergey Alexandrovich Kryukov 259
4 Garth J Lancaster 240
0 Sergey Alexandrovich Kryukov 10,764
1 Maciej Los 5,474
2 OriginalGriff 5,472
3 CPallini 3,819
4 BillWoodruff 3,594


Advertise | Privacy | Mobile
Web03 | 2.8.141030.1 | Last Updated 9 Mar 2012
Copyright © CodeProject, 1999-2014
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