i used Macro to detected memory leaks. in ccConfig.h
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
#ifndef DBG_NEW
#include <crtdbg.h>
#define DBG_NEW new ( _NORMAL_BLOCK , FILE , LINE )
#endif
#ifndef DBG_STD_NEW
#define DBG_STD_NEW new ( _NORMAL_BLOCK , FILE , LINE )> #endif
#else
#ifndef DBG_NEW
#define DBG_NEW new
#endif
#ifndef DBG_STD_NEW
#define DBG_STD_NEW new(std::nothrow)
#endif
#endif
change code
new ==> DBG_NEW
new(std::nothrow) ===> DBG_STD_NEW
Interesting idea. It seems like this is a reasonable option as long as it’s also surrounded by #ifndef NDEBUG or whatever determines debug builds, or another flag that enables this NOT by default.
There’s also discussion of a cross-platform open source version: http://wyw.dcweb.cn/leakage.htm
And of course valgrind and XCode Analyzers/Instruments are similarly helpful in this regard.
Edit: and there was some work on custom cocos2d-x allocators by mannewalis that was able to output similar information. I think the code is in the latest versions (3.10+), but is disabled by default.
If you try the implement it as described here: https://msdn.microsoft.com/en-us/library/x98tx3cf(v=vs.140).aspx Microsoft macros are going to collide with some cocos functions, named realloc and free under certain cocos namespaces. I didn’t know how to solve that so I gave up on that. The method posed above might work, but then the leak detection only applied to where you explicitly used these custom allocation macros (you have to rewrite your entire code).