脚本内存泄漏

cocos2d-x c++ lua 游戏退出的时候有内存泄漏。

WARNING: Visual Leak Detector detected memory leaks!
---------- Block 7127 at 0x0224B940: 8 bytes ----------
Leak Hash: 0xFA092CC7, Count: 1, Total 8 bytes
Call Stack (TID 7204):
MSVCR120D.dll!operator new()
d:\program files (x86)\microsoft visual studio 12.0\vc\include\xmemory0 (848): Game.exe!std::_Wrap_alloc<std::allocatorstd::_Container_proxy >::allocate()
d:\program files (x86)\microsoft visual studio 12.0\vc\include\xtree (819): Game.exe!std::_Tree_alloc<0,std::_Tree_base_types<std::pair<void * const,std::vector<std::pair<enum cocos2d::ScriptHandlerMgr::HandlerType,int>,std::allocator<std::pair<enum cocos2d::ScriptHandlerMgr::HandlerType,int> > > >,std::allocator<std::pair<void * const,st() + 0xA bytes
d:\program files (x86)\microsoft visual studio 12.0\vc\include\xtree (794): Game.exe!std::_Tree_alloc<0,std::_Tree_base_types<std::pair<void * const,std::vector<std::pair<enum cocos2d::ScriptHandlerMgr::HandlerType,int>,std::allocator<std::pair<enum cocos2d::ScriptHandlerMgr::HandlerType,int> > > >,std::allocator<std::pair<void * const,st() + 0x8 bytes
d:\program files (x86)\microsoft visual studio 12.0\vc\include\xtree (890): Game.exe!std::_Tree_buy<std::pair<void * const,std::vector<std::pair<enum cocos2d::ScriptHandlerMgr::HandlerType,int>,std::allocator<std::pair<enum cocos2d::ScriptHandlerMgr::HandlerType,int> > > >,std::allocator<std::pair<void * const,std::vector<std::pair<enum c()
d:\program files (x86)\microsoft visual studio 12.0\vc\include\xtree (1003): Game.exe!std::_Tree_comp<0,std::_Tmap_traits<void *,std::vector<std::pair<enum cocos2d::ScriptHandlerMgr::HandlerType,int>,std::allocator<std::pair<enum cocos2d::ScriptHandlerMgr::HandlerType,int> > >,std::less<void *>,std::allocator<std::pair<void * const,std::ve()
d:\program files (x86)\microsoft visual studio 12.0\vc\include\xtree (1067): Game.exe!std::_Tree<std::_Tmap_traits<void *,std::vector<std::pair<enum cocos2d::ScriptHandlerMgr::HandlerType,int>,std::allocator<std::pair<enum cocos2d::ScriptHandlerMgr::HandlerType,int> > >,std::less<void *>,std::allocator<std::pair<void * const,std::vector<st()
d:\program files (x86)\microsoft visual studio 12.0\vc\include\map (96): Game.exe!std::map<void *,std::vector<std::pair<enum cocos2d::ScriptHandlerMgr::HandlerType,int>,std::allocator<std::pair<enum cocos2d::ScriptHandlerMgr::HandlerType,int> > >,std::less<void *>,std::allocator<std::pair<void * const,std::vector<std::pair<enum cocos2d()
f:\cocos2d\game-brnn\cocos2d\cocos\scripting\lua-bindings\manual\cocos2d\luascripthandlermgr.cpp (123): Game.exe!cocos2d::ScriptHandlerMgr::ScriptHandlerMgr()
f:\cocos2d\game-brnn\cocos2d\cocos\scripting\lua-bindings\manual\cocos2d\luascripthandlermgr.cpp (133): Game.exe!cocos2d::ScriptHandlerMgr::getInstance() + 0x27 bytes
f:\cocos2d\game-brnn\cocos2d\cocos\scripting\lua-bindings\manual\ccluaengine.cpp (284): Game.exe!cocos2d::LuaEngine::handleNodeEvent() + 0xD bytes
f:\cocos2d\game-brnn\cocos2d\cocos\scripting\lua-bindings\manual\ccluaengine.cpp (220): Game.exe!cocos2d::LuaEngine::sendEvent() + 0xF bytes
f:\cocos2d\game-brnn\cocos2d\cocos\base\ccscriptsupport.cpp (220): libcocos2d.dll!cocos2d::ScriptEngineManager::sendNodeEventToLua() + 0x13 bytes
f:\cocos2d\game-brnn\cocos2d\cocos\2d\ccnode.cpp (1306): libcocos2d.dll!cocos2d::Node::onEnter() + 0xB bytes
f:\cocos2d\game-brnn\cocos2d\cocos\2d\cccamera.cpp (385): libcocos2d.dll!cocos2d::camera::onEnter()
f:\cocos2d\game-brnn\cocos2d\cocos\2d\ccnode.cpp (1297): libcocos2d.dll!cocos2d::Node::onEnter() + 0x16 bytes
f:\cocos2d\game-brnn\classes\gamescene.cpp (89): Game.exe!GameScene::onEnter() + 0xB bytes
f:\cocos2d\game-brnn\cocos2d\cocos\base\ccdirector.cpp (1120): libcocos2d.dll!cocos2d::Director::setNextScene() + 0x1E bytes
f:\cocos2d\game-brnn\cocos2d\cocos\base\ccdirector.cpp (287): libcocos2d.dll!cocos2d::Director::drawScene()
f:\cocos2d\game-brnn\cocos2d\cocos\base\ccdirector.cpp (1397): libcocos2d.dll!cocos2d::DisplayLinkDirector::mainLoop()
f:\cocos2d\game-brnn\cocos2d\cocos\platform\win32\ccapplication-win32.cpp (93): libcocos2d.dll!cocos2d::Application::run() + 0xF bytes
f:\cocos2d\game-brnn\proj.win32\main.cpp (39): Game.exe!wWinMain() + 0x19 bytes
f:\dd\vctools\crt\crtw32\dllstuff\crtexe.c (466): Game.exe!wWinMainCRTStartup()
kernel32.dll!BaseThreadInitThunk() + 0x12 bytes
ntdll.dll!RtlInitializeExceptionChain() + 0x63 bytes
ntdll.dll!RtlInitializeExceptionChain() + 0x36 bytes
Data:
1C 14 5B 07 00 00 00 00 …[… …

---------- Block 7120 at 0x07052A00: 36 bytes ----------
Leak Hash: 0x37408879, Count: 1, Total 36 bytes
Call Stack (TID 6500):
MSVCR120D.dll!operator new()
f:\cocos2d\game-brnn\classes\appdelegate.cpp (89): Game.exe!AppDelegate::applicationDidFinishLaunching() + 0x7 bytes
f:\cocos2d\game-brnn\cocos2d\cocos\platform\win32\ccapplication-win32.cpp (75): libcocos2d.dll!cocos2d::Application::run() + 0xF bytes
f:\cocos2d\game-brnn\proj.win32\main.cpp (39): Game.exe!wWinMain() + 0x19 bytes
f:\dd\vctools\crt\crtw32\dllstuff\crtexe.c (466): Game.exe!wWinMainCRTStartup()
kernel32.dll!BaseThreadInitThunk() + 0x12 bytes
ntdll.dll!RtlInitializeExceptionChain() + 0x63 bytes
ntdll.dll!RtlInitializeExceptionChain() + 0x36 bytes
Data:
58 56 99 00 01 00 00 00 1A 00 00 00 00 00 00 00 XV… …
00 00 00 00 00 CD CD CD 00 CD CD CD 00 00 00 00 … …
00 00 00 00

---------- Block 7122 at 0x07052AB0: 36 bytes ----------
Leak Hash: 0xC0D14840, Count: 1, Total 36 bytes
Call Stack (TID 6500):
MSVCR120D.dll!operator new()
f:\cocos2d\game-brnn\classes\appdelegate.cpp (90): Game.exe!AppDelegate::applicationDidFinishLaunching() + 0x7 bytes
f:\cocos2d\game-brnn\cocos2d\cocos\platform\win32\ccapplication-win32.cpp (75): libcocos2d.dll!cocos2d::Application::run() + 0xF bytes
f:\cocos2d\game-brnn\proj.win32\main.cpp (39): Game.exe!wWinMain() + 0x19 bytes
f:\dd\vctools\crt\crtw32\dllstuff\crtexe.c (466): Game.exe!wWinMainCRTStartup()
kernel32.dll!BaseThreadInitThunk() + 0x12 bytes
ntdll.dll!RtlInitializeExceptionChain() + 0x63 bytes
ntdll.dll!RtlInitializeExceptionChain() + 0x36 bytes
Data:
78 71 99 00 01 00 00 00 1B 00 00 00 00 00 00 00 xq… …
00 00 00 00 00 CD CD CD 00 CD CD CD 00 00 00 00 … …
00 00 00 00

---------- Block 7125 at 0x072F47E0: 16 bytes ----------
Leak Hash: 0x807C8A52, Count: 1, Total 16 bytes
Call Stack (TID 6500):
MSVCR120D.dll!operator new()
f:\dd\vctools\crt\crtw32\heap\newopnt.cpp (18): Game.exe!operator new() + 0x9 bytes
f:\cocos2d\game-brnn\cocos2d\cocos\scripting\lua-bindings\manual\cocos2d\luascripthandlermgr.cpp (133): Game.exe!cocos2d::ScriptHandlerMgr::getInstance() + 0xC bytes
f:\cocos2d\game-brnn\cocos2d\cocos\scripting\lua-bindings\manual\ccluaengine.cpp (284): Game.exe!cocos2d::LuaEngine::handleNodeEvent() + 0xD bytes
f:\cocos2d\game-brnn\cocos2d\cocos\scripting\lua-bindings\manual\ccluaengine.cpp (220): Game.exe!cocos2d::LuaEngine::sendEvent() + 0xF bytes
f:\cocos2d\game-brnn\cocos2d\cocos\base\ccscriptsupport.cpp (220): libcocos2d.dll!cocos2d::ScriptEngineManager::sendNodeEventToLua() + 0x13 bytes
f:\cocos2d\game-brnn\cocos2d\cocos\2d\ccnode.cpp (1306): libcocos2d.dll!cocos2d::Node::onEnter() + 0xB bytes
f:\cocos2d\game-brnn\cocos2d\cocos\2d\cccamera.cpp (385): libcocos2d.dll!cocos2d::camera::onEnter()
f:\cocos2d\game-brnn\cocos2d\cocos\2d\ccnode.cpp (1297): libcocos2d.dll!cocos2d::Node::onEnter() + 0x16 bytes
f:\cocos2d\game-brnn\classes\gamescene.cpp (89): Game.exe!GameScene::onEnter() + 0xB bytes
f:\cocos2d\game-brnn\cocos2d\cocos\base\ccdirector.cpp (1120): libcocos2d.dll!cocos2d::Director::setNextScene() + 0x1E bytes
f:\cocos2d\game-brnn\cocos2d\cocos\base\ccdirector.cpp (287): libcocos2d.dll!cocos2d::Director::drawScene()
f:\cocos2d\game-brnn\cocos2d\cocos\base\ccdirector.cpp (1397): libcocos2d.dll!cocos2d::DisplayLinkDirector::mainLoop()
f:\cocos2d\game-brnn\cocos2d\cocos\platform\win32\ccapplication-win32.cpp (93): libcocos2d.dll!cocos2d::Application::run() + 0xF bytes
f:\cocos2d\game-brnn\proj.win32\main.cpp (39): Game.exe!wWinMain() + 0x19 bytes
f:\dd\vctools\crt\crtw32\dllstuff\crtexe.c (466): Game.exe!wWinMainCRTStartup()
kernel32.dll!BaseThreadInitThunk() + 0x12 bytes
ntdll.dll!RtlInitializeExceptionChain() + 0x63 bytes
ntdll.dll!RtlInitializeExceptionChain() + 0x36 bytes
Data:
70 0D 9B 00 90 48 2F 07 30 48 2F 07 00 00 00 00 p…H/. 0H/…

如果程序都退出了,就无所谓内存泄露了。你这里说的内存泄露可能是一些全局变量或者是单例对象。

是的。大部分是由单例造成的。