This question already has an answer here:
Lets assume I run such a code
Task.Factory.StartNew(...).ContinueWith(...);
I don't store reference for neither of two created tasks so can I be sure that they won't be disposed before starting or at the process of executing? If yes then where do reference to these tasks are being held?
A reference to a TPL
Task
is held by the system under two conditions: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.Should you dispose Tasks?
Stephen Toub says: