SQLDataReader

M

Michael Jackson

My application is using the SQLDataReader to retreive and itereate thru rows
of data from SQL Server, then for each row of that SQLDataReader, selects
related rows from another table via yet another SQLDataReader. When I finish
with a row, I do a SQLDataReader.Close and set it to nothing, but my .NET
Memory Profiler shows that the instances of the SQLDataReaders are never
being disposed.

Am I missing something?

Thanks,
Michael
 
M

Michael Jackson

I've read Dispose, Finalize, etc till I'm blue in the face. How to I
implement Dispose on a SQLDataReader if it's not in a class?

Michael
 
S

Sahil Malik

Michael,

First of all .. I'm glad a pop star of your stature is coding in .NET. ;-).

Secondly - about the dispose - you don't !!! The thing about Dispose is -
it's just as good as the class implemented it. I posted this on my blog a
while back
http://dotnetjunkies.com/WebLog/sahilmalik/archive/2004/11/12/31798.aspx

While that post is mostly about "Connection Pooling" - it does shed some
light on "Why Dispose isn't the magic bullet". (Albeit it's still good, and
you should call it when you can).

The best you can do is to wait until GC kicks in and cleans that up for you.
.... while it can be argued that .NET should have given you the ability to
knock out an object if you decided to - that is what you had to do in C++ -
you had to delete for every new you did. And that lead to NOTHING BUT
PROBLEMS !!!. Garbage collector and the non deterministic model is awesome -
even though it is barely 2% shorter of the bestest possible picture - it's
still pretty damn good for no effort on your part.

- Sahil Malik
http://dotnetjunkies.com/weblog/sahilmalik
 
M

Michael Jackson

So, am I to assume that 6900 plus/minus SQLDataReader objects that have not
been disposed is OK, given 1 gig of RAM and assuming .NET Memory Profiler is
correct, and that I know how to read it?

Michael
 
M

Michael Jackson

Thanks for the reply.

I've tried GC.Collect. No such luck. My other thought was that creating a
thread to run the process was the problem. I removed threading, still the
SQLDataReaders continue to go un-disposed. I'm perplexed.

Michael
 
E

Edward Diener

Sahil Malik said:
Michael,

First of all .. I'm glad a pop star of your stature is coding in .NET.
;-).

Secondly - about the dispose - you don't !!! The thing about Dispose is -
it's just as good as the class implemented it. I posted this on my blog a
while back
http://dotnetjunkies.com/WebLog/sahilmalik/archive/2004/11/12/31798.aspx

While that post is mostly about "Connection Pooling" - it does shed some
light on "Why Dispose isn't the magic bullet". (Albeit it's still good,
and you should call it when you can).

The best you can do is to wait until GC kicks in and cleans that up for
you. ... while it can be argued that .NET should have given you the
ability to knock out an object if you decided to - that is what you had to
do in C++ - you had to delete for every new you did. And that lead to
NOTHING BUT PROBLEMS !!!

Evidently you have never heard of smart pointers in C++.
. Garbage collector and the non deterministic model is awesome - even
though it is barely 2% shorter of the bestest possible picture - it's still
pretty damn good for no effort on your part.

Awesome except when one has to deal with resources, as the OP does. Then it
is flawed where C++ is not.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top