Click here to Skip to main content
15,891,372 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How can we use in real time.

Can any one help me on this.
Posted
Comments
Sergey Alexandrovich Kryukov 9-Mar-12 0:43am    
Aha, real time... what do you mean by that?
--SA

Nice article shares when and how to use finalize and dispose in .NET

Refer: http://www.devx.com/dotnet/Article/33167[^]
 
Share this answer
 
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
 
Share this answer
 
v2
Comments
member60 9-Mar-12 0:58am    
agreed.
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[^]
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 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
Sergey Alexandrovich Kryukov 9-Mar-12 0:50am    
I added additional answer with a reference to MSDN help page an my short article, please see.
--SA
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.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 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
Sergey Alexandrovich Kryukov 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900