Home Dashboard Directory Help

Dynamically-initialized static std::string leaking by Rodarin


 as Fixed Help for as Fixed

Sign in
to vote
Type: Bug
ID: 622001
Opened: 11/15/2010 8:20:15 AM
Access Restriction: Public
User(s) can reproduce this bug


An internally-linked static array of std::string within a DLL shows as leaked memory when the hosting application shuts down.
Sign in to post a comment.
Posted by Rodarin on 4/6/2011 at 6:35 AM
Thanks for looking into this. I am still concerned by this issue, since it was not present in VC8, but is in VC10. Also, I am assuming you meant that you fixed the const std::strings, not CStrings? If so, is this going to be in the next service pack?

Unfortunately, I cannot modify the actual production code where this manifests due to licensing restrictions, and disabling leak reporting is not a reasonable solution, as there are many other potential leaks that we don't want to miss.
Posted by Microsoft on 4/5/2011 at 2:58 PM

Thanks for the report. I have fixed the const CStrings in the MFC DLLs, so they won't show as leaking, but otherwise MFC is doing the best it can in this situation. You have memory that was allocated during your DLL initialization (before the MFC DLL was loaded), so your memory will not have been freed when the MFC DLL is unloaded (this is Windows loader behavior). So the only way to get the leaks reported accurately will be to disable MFC leak reporting (by calling AfxEnableMemoryLeakDump(FALSE) somewhere in your application) and then calling _CrtDumpMemoryLeaks() during the unloading of your DLL. You may have to implement a DLLMain in your DLL and dump the memory leaks during the DLL_DETACH_PROCESS. Or you can add something like the following to one of your CPP modules to dump leaks:

    _DEBUG_STATE() {}
    ~_DEBUG_STATE() { _CrtDumpMemoryLeaks(); }


I added the above code to your names.cpp file, and added a call to AfxEnableMemoryLeakDump(FALSE); in CCRTTestApp::InitInstance and no leaks were reported. I hope this helps.

Pat Brenner
Visual C++ Libraries Development
Posted by Microsoft on 11/15/2010 at 6:15 PM
Thanks for your feedback.
We are routing this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will follow-up with your issue.
Posted by Microsoft on 11/15/2010 at 9:21 AM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Sign in to post a workaround.
File Name Submitted By Submitted On File Size  
CRTTest2.zip 11/15/2010 136 KB
CRTTest2.zip 11/15/2010 136 KB