Skip to content

Instantly share code, notes, and snippets.

@dirkgroot
Last active January 25, 2019 15:18
Show Gist options
  • Save dirkgroot/9bdf9b1963b5ecc8cdb9b778149f929c to your computer and use it in GitHub Desktop.
Save dirkgroot/9bdf9b1963b5ecc8cdb9b778149f929c to your computer and use it in GitHub Desktop.
Mono memory leak reproduction
using System;
using System.Threading;
using System.Threading.Tasks;
namespace TimerTest
{
public static class Program
{
private static int tickCount;
public static void Main()
{
StartSleepingTask();
StartSleepingTask();
while(true)
{
for(var i = 0; i < 1000; i++)
{
ThreadPool.UnsafeQueueUserWorkItem(Tick, null);
Thread.Sleep(10);
}
GC.Collect();
}
// ReSharper disable once FunctionNeverReturns
}
private static void StartSleepingTask()
{
var task1 = new Task(() => Thread.Sleep(TimeSpan.FromDays(24)));
task1.Start();
}
private static void Tick(object obj)
{
tickCount++;
if(tickCount % 1000 != 0) return;
Console.WriteLine($"Ticks: {tickCount}");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment