Hi
I have an application that needs to frequently backup a dataset and revert to that backup if the users decides to cancel an action.
There is a global dataset created at the top of the class:
DataSet database = null;
Every time a form is opened the main dataset is copied into the created variable:
database = AppModel.Instance.Data.Data.Copy();
The problem is that every time the form is opened the memory increases by quite a lot and is never released.
I've tried disposing the database variable after it's been used but the memory still remains high - This has left me to believe that the DataSet.Copy() method allocates to new memory every time.
Any suggestions to free up the memory would be greatly appreciated.
Regards,
Jason
Loading
VulpesPosted May 11, 2011, 9:24 AM
Are you binding to it at all?
Jason NesbittPosted May 11, 2011, 7:43 AM
We changed the cancel action to do this (The copiedDataSet was made from the originalDataSet just before the form opens):
originalDataSet.Dispose();
originalDataSet = null;
originalDataSet = copiedDataSet;
copiedDataSet.Dispose();
copiedDataSet = null;
GC.Collect();
It occasionally works the first time but doesn't on all of the other times. The memory still increases and isn't released.
Cheers,
Jason
VulpesPosted May 11, 2011, 6:49 AM
So could you be hanging on to a reference to the original DataSet somewhere? If so, then you need to set it to null after calling Dispose().
If you don't think this is happening or it's a very large DataSet, then you could try calling GC.Collect() after the copying operation to force an immediate garbage collection.
Jason NesbittPosted May 11, 2011, 6:38 AM
Sadly it didn't work.
The variable is declared as static globally so there is definitely only one instance of it but the DataSet.Copy() method still increases the memory every time the DataSet is copied to it.
VulpesPosted May 11, 2011, 6:33 AM
static DataSet database = null;