I created an example C # console application that reads file data in an byte array and converts the byte array to the sixth line. This requires a lot of memory, and it does not free up memory after shutdown, I also reset the values โโof the variables used.
Here is a sample code:
string filename = @"F:\\AVSEQ09.DAT"; //file size is 32 MB string hexData = null; byte[] fileDataContent = File.ReadAllBytes(filename); if (fileDataContent != null) hexData = BitConverter.ToString(fileDataContent); fileDataContent = null; hexData = null; //GC.Collect(); Console.ReadKey();
If I run this code, it takes 433 MB of personal working set, and if I uncomment the call to GC.collect, memmory will go down to 6 MB. Why should I explicitly call GC.collect, is it bad to invoke GC.collect explicitly, how can I free memmory (up to 6 MB) without invoking GC.collect?
source share