I would like to write the following code in c#. a) small console application that simulates memory leak. b) small console application that would invoke the above application and
I have tried to use the approach, described in the accepted answer, but it didn't work - it looks like compiler or runtime have optimized this away.
I have found the simplest modification which makes this work:
var rnd = new Random();
var list = new List<byte[]>();
while (true)
{
byte[] b = new byte[1024];
b[rnd.Next(0, b.Length)] = byte.MaxValue;
list.Add(b);
Thread.Sleep(10);
}
This code makes application consume more and more memory.