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.
.NET ProgrammingProgrammingDatabases

Avatar of undefined
Last Comment
mastoo

8/22/2022 - Mon
mastoo

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.
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.
lostinthegame

ASKER
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.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
ASKER CERTIFIED SOLUTION
Jacques Bourgeois (James Burger)

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
mastoo

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.