A reference to a TPL Task
is held by the system under two conditions:
- The Task is scheduled
- The Task is running
Upon completion of the Task
and any child tasks, the reference is thrown away. References in your code will behave as expected.
I believe you have some confusion regarding garbage collection and Dispose
. This question may enlighten you.
Difference between destructor, dispose and finalize method
Destructor implicitly calls the Finalize method, they are technically same. Dispose is available with those object which
implements IDisposable interface...
Should you dispose Tasks?
Stephen Toub says:
No. Don’t bother disposing of your tasks.
https://devblogs.microsoft.com/pfxteam/do-i-need-to-dispose-of-tasks/