I have a most simple app with one button. With each click a dummy byte array of 100 MB is allocated. After that, a garbage collection is started and then the used memory is printed out:
b.TouchUpInside += (object sender, EventArgs e) => {
byte[] q = new byte[100 * 1024 * 1024];
long m = GC.GetTotalMemory(forceFullCollection:true);
Debug.WriteLine("Mem: {0}", m);
};
After that, the scope of the byte array variable goes away.
Click the button 20 times. I would believe that the log always shows more or less 100 MB. But the reality is: The memory usage increases! 200MB, 300MB, 400MB, 500MB, 600MB, …
It does not matter which GC I use (Bohem or SGen). Or if I use Android instead of iOS.
However, if I make a Windows 8 app with Visual Studio, then the unused memory is collected!
I have found two pages that might relate to this problem:
stackoverflow.com/questions/8764258/triggering-garbage-collection-in-mono
lists.ximian.com/pipermail/mono-list/2009-November/043764.html
But I just cannot believe it. Can anybody explain to me why the GC does not work in this very, very simple case? And how I can trust the Mono GC in the future in real life apps?