Thread inside thread = Memory leak

semorri's Avatar, Join Date: Apr 2009
Newbie Member
Can anyone explain why this causes a memory leak? static void Main() { Thread outerThread = new Thread(delegate() { while (true) { Thread innerThread = new Thread(delegate() { }); innerThread.Start(); Thread.Sleep(10); } }); outerThread.Start(); Application.Run(); }By the way, if instead of creating an inner thread I just create an object, the garbage collector does its job and no memory leak occurs.
0
ljlong's Avatar
Go4Expert Member
I think this is just like in java the garbage collector will not clean up orphan threads.
0
semorri's Avatar, Join Date: Apr 2009
Newbie Member
The same example in Java does not leak.