Thread garbage collection
Posted on 2004-10-27
I'm sure this is an easy question for C# thread gurus but please enlighten a recent C++/MFC transplant.
I was just reading about timers in C# and I came across the following snippet in MSDN.
Note As long as you are using a Timer, you must keep a reference to it. As with any managed object, a Timer is subject to garbage collection when there are no references to it. The fact that a Timer is still active does not prevent it from being collected.
This got me thinking about my current design in which I utilize threads fairly heavily. Does this apply to threads also? I have not been keeping references to the threads I create, but it hasn't seemed to cause a problem yet.
Does this mean they could just be removed by garbage collector even though they are in the process of doing work??
public void StartServerThread()
ServerThread s = new ServerThread();
Thread t = new Thread(new ThreadStart(s.ThreadProcReceive));
t.IsBackground = true;
// will thread t eventually be collected once I exit this function?