Null out CancellationTokenSource._timer on Dispose/Cancel (#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)
commit0af70b614ded7636e6615bf035bbd5149670142b
tree897ec8aac56cbea9abc9dd5eda12dcac838417f0
parent7c04af489975d715d314a86177a47061d9ac9d75
Null out CancellationTokenSource._timer on Dispose/Cancel (#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.
src/System.Private.CoreLib/src/System/Threading/CancellationTokenSource.cs