Skip to content

Threads inside threads = Memory Leak

Steven

Asked Apr 22, 2009, 6:46 AM EDT1 answer
Share
LinkedInX

Can anyone explain why this causes a memory leak?

C#
        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.

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    Thanks.

    I am facing same problem.

    Can you please provide the object code. How did you implement that ?
    0