A (not so) basic question.

  • Thread starter Thread starter Roland
  • Start date Start date
Cor,
No that guy is "correct", note that he states "The only difference is that
Dispose *also* clears the connection
string."

Notice the word "also" in there; using Reflector (or ILDASM) one can see
that SqlConnection.Dispose(Boolean) clears the connection string, then calls
Close. Dispose also does some pool cleanup work...

--
Hope this helps
Jay B. Harlow [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net


| Herfried,
|
| You mean that this guy is wrong, I think that somebody has to inform him
| before things go really wrong.
| Because that you have seen this, than maybe can you send him a message.
|
|
http://groups.google.com/group/microsoft.public.dotnet.framework.adonet/msg/515919344c3c556a
|
| The only thing you can say is that the dispose is generic used in the
using
| statement.
| But in that is as well not generic a catch, something I am not so happy
| with,
|
| Cor
|
| "Herfried K. Wagner [MVP]" <[email protected]> schreef in bericht
| | >> Feel free to do it that way.
| >>
| >> You probably set as well all used values at null at the end of a
method?
| >
| > Sorry Cor, but Göran is right. It definitely makes sense to call the
| > 'Dispose' method whenever its available because implementing the
| > 'IDisposable' interface simply says "call the 'Dispose' method after
using
| > the object to free unmanaged resources occupied by the object". Even if
| > currently no unmanaged resources are released at all inside the method's
| > implementation, this might be the case in a future version. There are
| > some rare cases where I'd not call the 'Dispose' method, but the reason
| > for this is mainly that I do not care about the time when the resources
| > are released.
| >
| > --
| > M S Herfried K. Wagner
| > M V P <URL:http://dotnet.mvps.org/>
| > V B <URL:http://classicvb.org/petition/>
|
|
 
Jay,

The guy is writing "one of them is enough", not explitly telling which and
as I remember some more messages from him in the AdoNet newsgroup he points
more on the close than the dispose. I know that dispose does something more,
the question is if it is adding functionality and should be therefore in the
code.

I can make a piece of program like this.
\\\
For i As Integer = 0 To 1000000
dt1.Rows(i)("counter") = 1
ds.Dispose()
Next
///
It does nothing (not even spent much time). However in my opinion does it
suggest something that not is done and should therefore not be in a program.

That every dispose acts as well as a close where that should be done is
obvious. The using is (as you know) from the first day in C# and therefore
that is needed.

Just my opinion.

Cor

Jay B. Harlow said:
Cor,
No that guy is "correct", note that he states "The only difference is that
Dispose *also* clears the connection
string."

Notice the word "also" in there; using Reflector (or ILDASM) one can see
that SqlConnection.Dispose(Boolean) clears the connection string, then
calls
Close. Dispose also does some pool cleanup work...

--
Hope this helps
Jay B. Harlow [MVP - Outlook]
.NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net


| Herfried,
|
| You mean that this guy is wrong, I think that somebody has to inform him
| before things go really wrong.
| Because that you have seen this, than maybe can you send him a message.
|
|
http://groups.google.com/group/microsoft.public.dotnet.framework.adonet/msg/515919344c3c556a
|
| The only thing you can say is that the dispose is generic used in the
using
| statement.
| But in that is as well not generic a catch, something I am not so happy
| with,
|
| Cor
|
| "Herfried K. Wagner [MVP]" <[email protected]> schreef in bericht
| | >> Feel free to do it that way.
| >>
| >> You probably set as well all used values at null at the end of a
method?
| >
| > Sorry Cor, but Göran is right. It definitely makes sense to call the
| > 'Dispose' method whenever its available because implementing the
| > 'IDisposable' interface simply says "call the 'Dispose' method after
using
| > the object to free unmanaged resources occupied by the object". Even
if
| > currently no unmanaged resources are released at all inside the
method's
| > implementation, this might be the case in a future version. There are
| > some rare cases where I'd not call the 'Dispose' method, but the
reason
| > for this is mainly that I do not care about the time when the
resources
| > are released.
| >
| > --
| > M S Herfried K. Wagner
| > M V P <URL:http://dotnet.mvps.org/>
| > V B <URL:http://classicvb.org/petition/>
|
|
 
Back
Top