Need explicit OleDbCommand Dispose() for volume queries

  • Thread starter Thread starter Guy
  • Start date Start date
G

Guy

My application process records...lots of records. I typically read 85K
records from one Ms-Access table, then for each records of that
table , I have to read 3 others tables (in separate Ms-Access DB)
having hundreds of thousands records each, then I insert even more
records in to another table, yet another db.

I recently experienced an OUT_OF_MEMORY exception from the OleDb
driver. In the task manager, I could see the memory getting chewed
several megs a second. Since I only have one dbReader open at a time,
I was wondering what was causing this memory leak. I found a solution
by experimenting, and it involves calling Dispose() after every use of
all my OleDbCommand objects.

Is this normal ? Is there a better way to do this. Postings are not
cleared as to wether it is necessary to call Dispose explicitely.

Thanks.
 
Hello,

if you don't call Dispose() on an instance of an object, unmanaged memory
will eventually be reclaimed by the garbage collector.

Since the GC collects the objects on a seperate thread, you may receive
OutOfMemory exceptions if the GC cannot reclaim enough memory in a timely
fashion.

As a rule of thumb: If an object implements IDisposable, it does it for a
reason, so call it. Most of the time, it's for disposing unmanaged
resources.

Best regards,
Henning Krause
 
Back
Top