Null out CancellationTokenSource._timer on Dispose/Cancel (dotnet/coreclr#20410)
authorStephen Toub <stoub@microsoft.com>
Mon, 15 Oct 2018 19:44:57 +0000 (15:44 -0400)
committerGitHub <noreply@github.com>
Mon, 15 Oct 2018 19:44:57 +0000 (15:44 -0400)
commit5c9d5d32d363d073a60fa66663dcf4794985b6a0
treeab5665b3837d351feec527b04cfbcc4308692911
parent717546b296d0274cb4324db4d9e325ecec08b1b3
Null out CancellationTokenSource._timer on Dispose/Cancel (dotnet/coreclr#20410)

We already Dispose the Timer in such cases, but we don't null out the field.  That's generally fine, unless an errant CancellationToken is held onto somewhere that references the CancellationTokenSource, in which case it in turn may end up keeping the Timer alive and whatever its delegate/state reference, prolonging their GC unnecessarily.  Minor, but good house keeping, as CancellationTokens can be used in a manner that makes them longer-lived than expected.

Commit migrated from https://github.com/dotnet/coreclr/commit/0af70b614ded7636e6615bf035bbd5149670142b
src/coreclr/src/System.Private.CoreLib/src/System/Threading/CancellationTokenSource.cs