Re: Close() and Dispose()
From: Val Mazur (group51a_at_hotmail.com)
Date: 02/26/05
- Next message: Raphaël Désalbres: "Problem with SQL Server Script..."
- Previous message: Val Mazur: "Re: Insert SQL Error"
- In reply to: alx: "Close() and Dispose()"
- Next in thread: Sahil Malik: "Re: Close() and Dispose()"
- Reply: Sahil Malik: "Re: Close() and Dispose()"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 25 Feb 2005 21:16:58 -0500
Hi,
Dispose should close connection as well, but main purpose of Dispose not to
close the connection but to release the resources for the unmanaged code
inside of the class. If you do not call Dispose method you could face
situation when resources are not freed until you close your application. It
could lead to the fact when memory will grow and will not be released even
if you do not use objects anymore. Garbage Collector will not release memory
just because it does not know anything about unmanaged resources.
-- Val Mazur Microsoft MVP http://xport.mvps.org "alx" <alx@icnsoftware.com> wrote in message news:1109323147.659445.56890@f14g2000cwb.googlegroups.com... > On some documentation about ADO.NET, I've found that, during the close > of a IDbConnection, is a "best practice" to close a connection with > these lines of code: > > connection.Close(); > connection.Dispose(); > > For example, Microsoft Data Access Application Block uses this code to > close connection. Also they call Dispose method for others ADO.NET > objects (Command, DataAdapter). > > I'd like to know if it's really necessary to close a Connection always > with this 2 lines of code and call Dispose method for Command or > DataAdapter objects. > > Thanks. >
- Next message: Raphaël Désalbres: "Problem with SQL Server Script..."
- Previous message: Val Mazur: "Re: Insert SQL Error"
- In reply to: alx: "Close() and Dispose()"
- Next in thread: Sahil Malik: "Re: Close() and Dispose()"
- Reply: Sahil Malik: "Re: Close() and Dispose()"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|