Re: What is the difference between Dispose and close methods.

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Bhuwan Bhaskar wrote:
Hi all,

I am a bit confused about dispose and close methods. I will be glad if anyone explain the difference between them to me. Do they have relation with finalize method.

Thanks
Bhuwan


The Dispose method is used to tell the object to clean up everything as it's not going to be used any more. Once Dispose has been called, the object should not be possible to reuse.

The Close method on the other hand doesn't have to make the object unusable. Depending on what's appropriate for the class, it may be possible to reopen the object to reuse it.

--
Göran Andersson
_____
http://www.guffa.com
.



Relevant Pages

  • Re: What is the difference between Dispose and close methods.
    ... Use this method to close or release unmanaged resources such as files, streams, and handles held by an instance of the class that implements this interface. ... This method is, by convention, used for all tasks associated with freeing resources held by an object, or preparing an object for reuse. ... Also, as a finalizer is usually used as a backup when the object uses unmanaged resources, and the Dispose method then calls GC.SuppressFinalize to remove it from the finalization queue, it's pretty much only useful for objects that don't use any unmanaged resources. ...
    (microsoft.public.dotnet.framework)
  • Re: Performance... Need clarification
    ... > Is it necessary to dispose the objects created in procedure be disposed ... Things which implement IDisposable either contain unmanaged resources ... those resources (or not be able to reuse the existing resource) until ... disposed the stream, you may or may not be able to open the file for ...
    (microsoft.public.dotnet.framework.performance)
  • Re: SqlCe Insert Record Performance
    ... Calling Dispose gives you control. ... may not call it for minutes, hours or even days depending on the app. ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: Value unshopped Monster bash?
    ... Worthless, email me with location so I can dispose of it.... ... seems these are selling for between $3400 and $4000 depending on the ... buyers desperation. ...
    (rec.games.pinball)
  • Re: Display a bitmap from Win32, unmanaged code?
    ... So I said "hey, dispose of the bitmap" and I added ... The problem is that depending on what I do in the ... it seems that the bitmap is being disposed before the picturebox has ... Don't dispose the bitmap until you're done with it. ...
    (microsoft.public.dotnet.languages.csharp)