Explicitly freeing memory in c#
Recently I wrote a program which loads some CSV files in to DataTables and do some processing. These files are in large size and have nearly 1 million rows. When I load first file in to data table it works fine. But then I load the second file I get a “Out of Memory exception” even though first I make the previously loaded datatable to null. After searching for hours I found the following solution which solved my issue. var sourceDataTable = DataParserHelper .GetDataTableFromCsv( @"F:\FileSplitter\Data\5263\property_finance.csv" ); sourceDataTable.Clear(); sourceDataTable.Dispose(); sourceDataTable = null ; GC .Collect(); GC .WaitForFullGCComplete(); GC .WaitForPendingFinalizers(); if you make the datatable null what happens is it frees the Datatable from the rows and columns. But actually those rows and columns retained in the memory and those are not rea...