Re: ADO.NET and Dispose

Peter Foreman <[email protected]>
Newsgroups gmane.comp.windows.devel.dotnet.general
Message-ID <[email protected]>
--- Daniel Morgan <[email protected]> wrote:
> If I read the docs correctly, Close ( ) calls Dispose ( ) for the
> Connection.

Yes.

> However, I would like to know more about the proper way to dispose of
> resources.

If an object implements Dispose() then you should call it when you are completely done with that
object.  Ideally this will be asap after you are done with the object to achieve maximum
scalability.

If Dispose was put in an object's public interface then it is not without reason.  The problem is
there are different levels of importance for different resources, you may get away without calling
some.  Better safe than sorry though.  If you skip Dispose() then it may not do anything in
version 1 of the object you're using, but there is no saying that it will not be required in
version 2.  If there is one thing that COM taught it is always to program to the rules, even when
it appears you may be 'getting away with it' for now.

Peter


__________________________________________________
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup
http://fifaworldcup.yahoo.com

You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.