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 created mine with this code:
internal class Program
{
private static void Main(string[] args)
{
try
{
var limit = 9400;
while (true)
{
var thread = new Thread(() => IncreaseMemory(limit));
thread.Start();
}
}
catch (Exception)
{
// swallow exception
}
}
private static void IncreaseMemory(long limity)
{
var limit = limity;
var list = new List();
try
{
while(true)
{
list.Add(new byte[limit]); // Change the size here.
Thread.Sleep(1000); // Change the wait time here.
}
}
catch (Exception ex)
{
// do nothing
}
}
}