Last active
January 25, 2019 15:18
-
-
Save dirkgroot/9bdf9b1963b5ecc8cdb9b778149f929c to your computer and use it in GitHub Desktop.
Mono memory leak reproduction
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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