From 8536598b8e82fe2a2af83eda59e4e190c9303d16 Mon Sep 17 00:00:00 2001 From: Bill Holmes Date: Thu, 22 Aug 2024 09:27:18 -0400 Subject: [PATCH] Avoiding a memory leak in the Timer class SchedulerLoop Rather than calling the Sort overload that accepts the IComparer interface, we will call the overload that accepts the Comparison delegate. Both overloads end up in the same place eventually. There is a memory leak in the Mono runtime with the ldvirtftn opcode in a generic method. The opcode targets a generic interfaces method on a struct instance. Each time ldvirtftn is called an unbox trampoline is created. The ldvirtftn leak will be filed separately upstream but this simple change avoids the bug for this scenario. --- mcs/class/corlib/System.Threading/Timer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mcs/class/corlib/System.Threading/Timer.cs b/mcs/class/corlib/System.Threading/Timer.cs index 47c575466941..58c7fa126779 100644 --- a/mcs/class/corlib/System.Threading/Timer.cs +++ b/mcs/class/corlib/System.Threading/Timer.cs @@ -390,7 +390,7 @@ int RunSchedulerLoop () { var comparer = new TimerComparer(); if (needReSort) { - list.Sort(comparer); + list.Sort(comparer.Compare); needReSort = false; }