Alex Rivera | Logout

How to ignore false positive memory leaks from _CrtDumpMemoryLeaks?

Asked 2010-02-24T03:19:15.300
15

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 until after the main() (or WinMain) function. But is there any way of avoiding this? I use VS2008.

Edit
Report

1 Answer

1

1) You said:

It seems whenever there are static objects, _CrtDumpMemoryLeaks returns a false positive claiming it is leaking memory.

I don't think this is correct. EDIT: Static objects are not created on heap. END EDIT: _CrtDumpMemoryLeaks only covers crt heap memory. Therefore these objects are not supposed to return false positives. However, it is another thing if static variables are objects which themselves hold some heap memory (if for example they dynamically create member objects with operator new()).

2) Consider using _CRTDBG_LEAK_CHECK_DF in order to activate memory leak check at the end of program execution (this is described here: http://msdn.microsoft.com/en-us/library/d41t22sb(VS.80).aspx). I suppose then memory leak check is done even after termination of static variables.

answered 2010-04-08T14:01:48.137

Your Answer