Removing completed tasks from the <Tasks> list
I am using TPL in .net 4.0 to work with multiple tasks asynchronously. Below is the code snippet:
List<Task> TaskList = new List<Task>(); while (some condition) { var t = Task.Factory.StartNew( () = > doSomething () ); TaskList.Add(t) } //Wait for all tasks to complete Task.WaitAll(TaskList.toArray());
If the while loop runs for a long time, what happens to the size of the "TaskList"? I am concerned that this will take up significant memory if the while loop runs for days. Should I remove completed jobs from this list or are they automatically removed?
Is there any other way to optimize this in terms of memory?
+3
source share