Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C# (http://www.go4expert.com/forums/c-sharp/)
-   -   Thread inside thread = Memory leak (http://www.go4expert.com/forums/thread-inside-thread-memory-leak-t17044/)

semorri 22Apr2009 20:24

Thread inside thread = Memory leak
 
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.

ljlong 25Apr2009 01:31

Re: Thread inside thread = Memory leak
 
I think this is just like in java the garbage collector will not clean up orphan threads.

semorri 26Apr2009 04:40

Re: Thread inside thread = Memory leak
 
The same example in Java does not leak.


All times are GMT +5.5. The time now is 13:08.