,我在lua中使用ccp(x,y)和getContentSize()好像会造成内存泄露

我在我的项目中使用了lua,然后使用了一款叫做Visual Leak Detector的内存泄露检测工具,我在lua中使用ccp(x,y)和getContentSize()好像会造成内存泄露!

比如:local actionScale=CCMoveTo:create(0.2,ccp(self.P_items:getPositionX() - self.P_items:getContentSize().width,self.P_items:getPositionY()))

---------- Block 67459 at 0x03047BA0: 8 bytes ----------
Call Stack:
HINT: The following call stack may be incomplete. Setting “StackWalkMethod”
in the vld.ini file to “safe” instead of “fast” may result in a more
complete stack trace.
e:\cocos2d-x\cocos2d-x-2.2\scripting\lua\cocos2dx_support\luacocos2d.cpp (5410): card.win32.exe!tolua_Cocos2d_ccp00 + 0x7 bytes
0x5EABF89F (File and line number not available): lua51.dll!lua_close + 0x55FF bytes
0x00010661 (File and line number not available): (Module name unavailable)!(Function name unavailable)
Data:
00 00 80 3F 00 00 00 00

Call Stack:
HINT: The following call stack may be incomplete. Setting “StackWalkMethod”
in the vld.ini file to “safe” instead of “fast” may result in a more
complete stack trace.
e:\cocos2d-x\cocos2d-x-2.2\scripting\lua\cocos2dx_support\luacocos2d.cpp (14582): card.win32.exe!tolua_Cocos2d_CCNode_getContentSize00 + 0x7 bytes
0x5EABF89F (File and line number not available): lua51.dll!lua_close + 0x55FF bytes
0x00010661 (File and line number not available): (Module name unavailable)!(Function name unavailable)
Data:
00 00 F0 42 00 00 A0 41 …B…A …

:769: 楼主你获取的是什么控件的size呢?cocostudio创建的么?

是通过cocostudio创建的,应该是所有组件都会。
LuaCocos2d.cpp中
void* tolua_obj = Mtolua_new((CCPoint)(tolua_ret));
tolua_pushusertype(tolua_S,tolua_obj,“CCPoint”);
tolua_register_gc(tolua_S,lua_gettop(tolua_S));

好像没地方delete

你自己有调pure()么?

版主亲,木有听懂哈~:12:

哈,暂时没有用过lua语言,只知道C++版本在结束的时候应该调用几个pure()清理方法,不晓得lua需要不,我只晓得lua貌似不用自己管理内存。

SceneReader::sharedSceneReader()->purge();
GUIReader::shareReader()->purge();
ActionManager::purge();

以上是部分方法

问题解决了,通过ccp(x,y)和getContentSize()获得的CCpiont指针其实已经注册到lua的垃圾回收里了,需要添加
collectgarbage(“setpause”, 100)
collectgarbage(“setstepmul”, 5000)
对垃圾回收进行设置。

好吧,学习了~~欢迎加好友共同学习

楼主,我试了你推荐的内存工具
,但是我用的是lua的脚本,请问下怎么唷那个它来检测lua的内存?

楼主,我想请问下,加下面的代码你是加在哪里的?我的是直接加在入口lua文件的开头的,但是我发现这边即使是加了这个代码也还是一样的呢,运行得越久检测到的CPP,SIZE,CCC3之类的泄漏也就越多
– avoid memory leak
collectgarbage(“setpause”, 100)
collectgarbage(“setstepmul”, 5000)