[dba-VB] C#: When to Dispose

Michael Maddison michael at ddisolutions.com.au
Sat Aug 23 00:38:09 CDT 2008


Hi Gustav,

I rarely explicitly Dispose.  
I was aware that certain objects do require Disposing such as some
Streams and some database objects.
These days I use Using  'C#' not sure what the VB equivalent is.  

Browsing the article he makes it pretty clear that Dispose is mainly
used for unmanaged objects, so in your example
if you are using an unmanaged library then you should probably Dispose
it.  

If you are writing an API that uses unmanaged objects then as the
developer you should implement the IDispose Interface.

If your app is leaking memory then you may be missing Dispose calls.

cheers

Michael M


Hi all

Came across this article on the subject:

  http://www.devx.com/dotnet/Article/33167

and realise that I don't dispose objects that much and yet the code runs
- and most of the coding examples I see don't tell much about it.

Right now I'm writing some code to send a series of e-mails and the code
I found calls Dispose. That makes sense: Create the MailMessage object,
send the message, dispose object.

But what experience do you have? How keen are you about disposing
objects?

/gustav


_______________________________________________
dba-VB mailing list
dba-VB at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/dba-vb
http://www.databaseadvisors.com


No virus found in this incoming message.
Checked by AVG - http://www.avg.com
Version: 8.0.138 / Virus Database: 270.6.6/1626 - Release Date:
8/21/2008 6:54 PM




More information about the dba-VB mailing list