Clear Dataset

  • Thread starter Thread starter Ryan Miller
  • Start date Start date
R

Ryan Miller

I have a temporary dataset that I can't seem to throw away. I've tried clear
and dispose, but the GC never seems to reclaim the memory.

I have a windows form with a DataGrid on it with datasource set to this
temporary dataset. I have buttons that fill the dataset, manipulate it, and
clear it. It all works, but like I said, the GC doesn't reclaim the memory.
On repeated fill/manipulate/clear events the program memory just keeps
climbing. I know GC runs because it will climb by say 2 MB and then drop by
about 2k after the clear.

Why can't I get the memory footprint to drop down to around the initial
position before the first fill?

Anybody have a good method for tracking these memory leaks?

Thanks,
-Ryan
 
Hi Ryan,

I dont think that there is any memory leak, the GC has its own memory, as
well as windows OS has, so it's perfectly logic to think that if you use a
quantity of memory that you may need it back in a future time, using your
example that you create a dataset on a method, use it and then dispose it
all of this after the user clicked a button on the form, now if the user
click the button again, a new memory chunk is needed, so it would perform
better if the GC keeps the memory marked as used ( even as it's not ), in
the second request it already has control over the memory and it can give it
to the application faster.

A think that a similar logic should be implemented on the OS itself.



Cheers,
 
Wow, that was it. Once I minimized the form, all my memory was returned.

I won't bother with forcing the GC to collect like the article explains
because I'm just in the design/test phase of what will eventually be a
windows service.

Thanks again,
-Ryan


public static void ReclaimMemory()
{
System.GC.Collect();
System.GC.WaitForPendingFinalizers();
SetProcessWorkingSetSize( Process.GetCurrentProcess().Handle, -1, -1 );
}
 
Back
Top