Imagine that there is a method:
public static void Foo()
{
Timer timer = null;
timer = new Timer(
callback: _ =>
{
if (satisfied)
{
timer.Change(1000, Timeout.Infinite);
return;
}
timer.Dispose();
},
state: null,
dueTime: Timeout.Infinite,
period: Timeout.Infinite);
timer.Change(0, Timeout.Infinite);
}
When method Foo() finishes, the only thing that references timer is callback. And the only thing that references callback is timer. Will that circular referencing safe timer from garbage collection?