I am currently optimizing memory usage with a huge batch program. Most of the memory is used by various data tables. For example, my data table dataTableuses about 260 MB.
For example, the sentence in the accepted answer from the topic " What are the memory costs for storing data in the .NET DataTable? ". I am trying to remove the relevant data from a DataTable. This is my code:
GC.Collect();
List<ExpandoObject> expandoList = new List<ExpandoObject>();
foreach (DataRow dataRow in dataTable.Rows)
{
dynamic expandoItem = new ExpandoObject();
expandoItem.FieldName = dataRow["FieldName"].ToString();
expandoList.Add(expandoItem);
}
dataTable.Clear();
dataTable.Dispose();
dataTable = null;
GC.Collect();
I use Clear, Dispose and set to null because it is suggested in the following topic: Datatable.Dispose () will force it to be deleted from memory?
, . using (DataTable dataTable = ...), .
?
, DataTable?