Jump to content
Xtreme .Net Talk

Recommended Posts

Posted
If your class implements IDisposable, is it guaranteed to be called by the application that it was created in when the application exits? For example, you forgot to Dispose of a class or you have a class that has a static member which is implements IDisposable. In both cases, will the application call Dispose for you when it is exited?
Gamer extraordinaire. Programmer wannabe.
  • Administrators
Posted

IIRC Dispose will not be called automatically when the program exits. however if you override the finalize method in a class this will automatically be called (sometime after the object goes out of scope and before the application terminates).

MS info on the subject...

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/html/cpconfinalizedispose.asp

 

also

http://www.vbinfozine.com/a_disposable.shtml

has an idea or two.

 

if you are using C# though a new keyword 'using' can be used.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csspec/html/vclrfcsharpspec_8_13.asp

 

this will call the Dispose method automatically

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

  • *Experts*
Posted
The memory that belongs to managed objects will be released automatically and collected by the garbage collector when it is no longer needed (i.e. when the program exits). Memory for unmanaged resources (such as GDI32 objects) needs to be manually freed, though.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...