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
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.
Avatar of lostinthegame
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.
ASKER CERTIFIED SOLUTION
Avatar of Jacques Bourgeois (James Burger)
Jacques Bourgeois (James Burger)
Flag of Canada image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of mastoo
mastoo
Flag of United States of America image

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

The .NET Framework is not specific to any one programming language; rather, it includes a library of functions that allows developers to rapidly build applications. Several supported languages include C#, VB.NET, C++ or ASP.NET.

137K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo