How to ignore false positive memory leaks from _CrtDumpMemoryLeaks?

后端 未结 7 1236
[愿得一人]
[愿得一人] 2020-12-03 11:41

It seems whenever there are static objects, _CrtDumpMemoryLeaks returns a false positive claiming it is leaking memory. I know this is because they do not get destroyed unti

相关标签:
7条回答
  • 2020-12-03 12:38

    I found that if you tell it to check memory automatically after the program terminates, it allows all the static objects to be accounted for. I was using log4cxx and boost which do a lot of allocations in static blocks, this fixed my "false positives"...

    Add the following line, instead of invoking _CrtDumpMemoryLeaks, somewhere in the beginning of main():

    _CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
    

    For more details on usage and macros, refer to MSDN article:

    http://msdn.microsoft.com/en-us/library/5at7yxcs(v=vs.71).aspx

    0 讨论(0)
提交回复
热议问题