Problem freeing memory after using Fill method

  • Thread starter Thread starter Sean Flook
  • Start date Start date
S

Sean Flook

I am using a DataSet to get lookup tables from my database to use in a form
and when I have finished with the form I am clearing and then disposing of
the DataTables from the DataSet. When running the application against a
memory profiler I am finding that there are String Arrays still left with
the information from the DataTables. The Allocation Call Stack is as
follows:

StringStorage.SetCapacity(int)
DataColumn.SetCapacity(int)
RecordManager.set_RecordCapacity(int)
RecordManager.GrowRecordCapacity()
RecordManager.NewRecordBase()
DataTable.NewRecordFromArray(object[])
DataTable.LoadDataRow(object[], bool)
SchemaMapping.LoadDataRow(bool, bool)
DbDataAdapter.FillLoadDataRow(SchemaMapping)
DbDataAdapter.FillFromReader(object, string, IDataReader, int, int,
DataColumn, object)
DbDataAdapter.Fill(DataSet, string, IDataReader, int, int)
DbDataAdapter.FillFromCommand(object, int, int, string, IDbCommand,
CommandBehavior)
DbDataAdapter.Fill(DataSet, int, int, string, IDbCommand, CommandBehavior)
DbDataAdapter.Fill(DataSet, string)


I would have thought that disposing of the DataTable would have disposed of
the string array, but that does not seem to be the case. Is there any way of
doing this, or is it a known memory leak.

Sean
 
Sean,

Disposing tells the GC that when he starts can look if the memory from the
datatable can be released.

(That "can be" interesting when you did not completly instanced the
datatable and his references inside your method otherwise the GC does this
direct, with or without dispose when that is gone out of scope).

The memory it uses will be released (with or withouth the dispose) when
there are no references anymore to or from it.

Maybe can ,if you have added your datatable to a dataset, it helps you if
you do.
ds.tables(0).clear
ds.tables(0).remove if you really want to force it a little bit

When the datatable is set as a datasource than you can set that datasource
to nothing

However only when you really have to less memory of course.

I hope this helps,

Cor
 
Cor

Thanks for the reply, but I am already clearing the table and removing it
from the datasource, followed by clearing the datasource. I have also tried
GC.Collect() and the string array is still left.

Sean
 
Back
Top