Does C# stores references to tasks from TPL

.net, c#, task-parallel-library

Solution

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/

Problem

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?

Original source

Related problems