已答复 parallel_for_each casue memory leak!

  • Thursday, August 25, 2011 10:53 AM
     
     

     I just wrote a few code about PPL, as following:

            vector<wstring> testPath, retPath;
            testPath.push_back(L"niha");
            testPath.push_back(L"nnnn");
            parallel_for_each(testPath.begin(),testPath.end(),
                [/*retPath*/](wstring path)
            {
                // TODO:
            });

    After dubugging those code , memory leak happened. I tried google for the root cause, but found nothing of help?

    Does anyone ever get the same question?

All Replies

  • Thursday, August 25, 2011 10:55 AM
     
     

     I just wrote a few code about PPL, as following:

            vector<wstring> testPath, retPath;
            testPath.push_back(L"niha");
            testPath.push_back(L"nnnn");
            parallel_for_each(testPath.begin(),testPath.end(),
                [/*retPath*/](wstring path)
            {
                // TODO:
            });

    After dubugging those code , memory leak happened. I tried google for the root cause, but found nothing of help?

    Does anyone ever get the same question?

    I got this problem when I develop a MFC application.
  • Wednesday, August 31, 2011 8:32 PM
     
     

    I get memory leaks too using parallel_for in a very simplified test console application in VS2010:

     

    void test(int t)
    {
       for (int i = 0; i < t; i++)
          i = i;
    }

    int _tmain(int argc, _TCHAR* argv[])
    {
       _CrtSetDbgFlag(_CrtSetDbgFlag(_CRTDBG_REPORT_FLAG) | _CRTDBG_LEAK_CHECK_DF);
       Concurrency::parallel_for(0, 20000, test);
       return 0;
    }

     

    Using _crtBreakAlloc, it seems that the ThreadScheduler created in the following code (in ThreadScheduler.cpp) is never released:

     

     ThreadScheduler* ThreadScheduler::Create(__in const ::Concurrency::SchedulerPolicy& policy)
        {
            return new ThreadScheduler(policy);
        }

     

    Am I missing something or is there a bug in the PPL?

  • Wednesday, September 14, 2011 6:20 PM
     
     Answered

    AceLencho,

    Apologies for the delayed response.

    In VS 2010 some memory allocations were falsely reported as leaks by the CRT error reporting mechanism. This issues was fixed in the SP1.


    Artur Laksberg - MSFT