什么prevents被收集在C#中的主题? [英] What Prevents a Thread in C# from being Collected?
问题描述
在.NET中,在此之后code,什么机制被垃圾收集站Thread对象?
In .NET, after this code, what mechanism stops the Thread object from being garbage collected?
new Thread(Foo).Start();
GC.Collect();
是的,它是安全的假设的东西有一个参考线,我只是徘徊究竟是什么。出于某种原因,反射器不显示我的System.Threading,所以我不能把它挖出来自己(我知道MS发布了源$ C $ C对于.NET框架,我只是没有它方便)。
Yes, it's safe to assume something has a reference to the thread, I was just wandering what exactly. For some reason Reflector doesn't show me System.Threading, so I can't dig it myself (I know MS released the source code for .Net framework, I just don't have it handy).
推荐答案
运行时保持一个参考线,只要它正在运行。只要有人仍然保持引用GC不会收集它。
The runtime keeps a reference to the thread as long as it is running. The GC wont collect it as long as anyone still keeps that reference.
这篇关于什么prevents被收集在C#中的主题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!