Link to home
Start Free TrialLog in
Avatar of lostinthegame
lostinthegame

asked on

Memory Usage with DataSets never reduces

I have a vb.net windows form project that includes a dataset.  From my main form, the user can open a "load client" form that contains a datagridview.  When the "load client" form opens, I fill a dataset on the form from my sql ce database and then load the dataset into a datagridview.  The database I'm testing with has 10,000 records, and it causes the memory usage to skyrocket.  My issue is that when the user closes the form, the memory usage doesn't decrease.  When they open the "load client" form again, the memory usage almost doubles again.

The form closes using me.dispose, but it doesn't seem to have an effect on the memory usage.

How can I stop this from happening?  To me, it seems like the dataset fills, but the memory is never emptied, so each time I fill the dataset the memory just keeps increasing.
Avatar of mastoo
mastoo
Flag of United States of America image

Garbage collection won't run until certain thresholds are exceeded.  I know you said memory skyrockets, but it might not be enough.  To test this, add a couple of gc.collect calls to force garbage collection.  If this keeps the memory from increasing, you know nothing leaks and that is normal behavior.
Avatar of lostinthegame
lostinthegame

ASKER

That seems to work, the memory drops back down some now.  Do I need to continuously use gc.collect or just let it run as-is?

Without the garbage collector, the memory use goes from 70,000k to 200,000k on the first load, then to 400,000k.  If I repeatedly open and close the form, it climbs over a million.  I don't know if it makes a difference, but for these tests I have just been running the program in the debugger.
Also, I'm only using the task manager to measure the amount of memory that is being used.  From what I have found, that doesn't seem to be the best method, but I'm just trying to wrap my head around what's causing the memory usage to climb so high, and if it's an issue.
ASKER CERTIFIED SOLUTION
Avatar of Jacques Bourgeois (James Burger)
Jacques Bourgeois (James Burger)
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Yes, there are some good articles out there explaining gc but this behavior is in the name of efficiency.  And they always recommend against routinely explicitly forcing gc like that.  It's been a while but I think there are several gc counters in Performance monitor (PerfMon) that you can watch to get a better handle on this behavior in your program.