Memory leak when ThreadLocal<T> is used in cyclic graph
问题 I just came across this weird 'behavior' of the Garbage Collector concerning System.Threading.ThreadLocal<T> that I can't explain. In normal circumstances, ThreadLocal<T> instances will be garbage collected when they go out of scope, even if they aren't disposed properly, except in the situation where they are part of a cyclic object graph. The following example demonstrates the problem: public class Program { public class B { public A A; } public class A { public ThreadLocal<B> LocalB; }