RE: Trying to become one with the GC
"Jeroen Frijters" <[email protected]>
| Newsgroups | gmane.comp.windows.off-topic |
|---|---|
| Message-ID | <000f01ca0093$2505cc90$6f1165b0$@nu> |
Gough, Christopher wrote:
> Consider the following code:
>
> Thread t = null;
> for (int i = 0; i < 10; i++)
> {
> t = new Thread( new ThreadStart( Worker ) );
> t.Name = string.Format( "Worker Thread {0}", i );
> t.Start();
> }
>
> My threads go off on their merry way but I don't have any reference to
> the threads anymore. Are my poor helpless threads now at the mercy of
> the garbage collector? I suspect they are safe but I'm not 100%
> positive.
Threads that are running are considered "roots" by the GC, so as long as
they are running they won't be garbage collected.
Regards,
Jeroen