Steven

Steven

  • NA
  • 1
  • 0

Threads inside threads = Memory Leak

Apr 22 2009 10:46 AM

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.


Answers (1)