I have a program running on [STAThread]
in C#.
The program periodically creates instances of a class X and adds them to a list.
After a period of time, the tasks that these instances of X are required to perform are completed and the instance of the class is no longer needed.
Since I am running on a single thread, and many of these instances of X could be running at the same time and draining resources even though they are no longer needed, I would like to free resources when I know an instance of X is done with, so that my program doesn't slow down.
My code looks like:
public partial class Form1 : Form
{
List<X> myList = new List<X>();
...
}
I am wondering if:
- Performing the operation
myList.RemoveAt(0)
will remove all trace of the first instance of the class X from memory. - If there is a better way to do this.
Thanks! Chris