🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

lua/toLua memory leak

Started by
2 comments, last by utopico 21 years ago
A new posting conserning lua. We have are having quiet a lot of memoryleaks from the lua scripting system. We are using toLua to generate to the code. The memory leak appears when returning params by value instead of reference. As far as I understood toLua where supposed to take care of this? Btw we are using lua 4 and not 5. A typical example where a memoryleak will appear is below (a pkg file used for toLua): class GamePos2d{ public: GamePos2d(float x, float y); ~GamePos2d(); GamePos2d normalized(); } When calling normalized method a leak will appear and can be tracked down to the duplication of the GamePos2d object. It seems that the automatic deletion of the duplicate object does not work. We have also another leak that are comes from toLua/lua scripting. I have not been able to locate them, but are typically of 20-40 bytes long. These does not seem to come from the same problem though, i.e. will also be there without returning by value.
Advertisement
Any chance you can post the generated code for that?
/*** Lua binding: gp2d** Generated automatically by tolua 4.0 on 06/16/03 17:49:26.*/#include "tolua.h"/* Exported function */int tolua_gp2d_open (lua_State* tolua_S);void tolua_gp2d_close (lua_State* tolua_S);/* function to register type */static void toluaI_reg_types (lua_State* tolua_S){ tolua_usertype(tolua_S,"GamePos2d");}/* method: new of class  GamePos2d */static int toluaI_gp2d_GamePos2d_new00(lua_State* tolua_S){ if ( !tolua_istype(tolua_S,2,LUA_TNUMBER,0) || !tolua_istype(tolua_S,3,LUA_TNUMBER,0) || !tolua_isnoobj(tolua_S,4) ) goto tolua_lerror; else {  float x = ((float)  tolua_getnumber(tolua_S,2,0));  float y = ((float)  tolua_getnumber(tolua_S,3,0)); {  GamePos2d* toluaI_ret = (GamePos2d*)  new GamePos2d(x,y); tolua_pushusertype(tolua_S,(void*)toluaI_ret,tolua_tag(tolua_S,"GamePos2d")); } } return 1;tolua_lerror: tolua_error(tolua_S,"#ferror in function ''new''."); return 0;}/* method: delete of class  GamePos2d */static int toluaI_gp2d_GamePos2d_delete00(lua_State* tolua_S){ if ( !tolua_istype(tolua_S,1,tolua_tag(tolua_S,"GamePos2d"),0) || !tolua_isnoobj(tolua_S,2) ) goto tolua_lerror; else {  GamePos2d* self = (GamePos2d*)  tolua_getusertype(tolua_S,1,0); if (!self) tolua_error(tolua_S,"invalid ''self'' in function ''delete''"); delete self; } return 0;tolua_lerror: tolua_error(tolua_S,"#ferror in function ''delete''."); return 0;}/* method: raw_delete; called by garbage collector */static int tolua_GamePos2d_tolua_raw_delete(lua_State* tolua_S){  GamePos2d* self = (GamePos2d*)  lua_touserdata(tolua_S,1); delete self; return 0;}/* method: normalized of class  GamePos2d */static int toluaI_gp2d_GamePos2d_normalized00(lua_State* tolua_S){ if ( !tolua_istype(tolua_S,1,tolua_tag(tolua_S,"GamePos2d"),0) || !tolua_isnoobj(tolua_S,2) ) goto tolua_lerror; else {  GamePos2d* self = (GamePos2d*)  tolua_getusertype(tolua_S,1,0); if (!self) tolua_error(tolua_S,"invalid ''self'' in function ''normalized''"); {  GamePos2d toluaI_ret = (GamePos2d)  self->normalized(); {#ifdef __cplusplus void* toluaI_clone = new GamePos2d(toluaI_ret);#else void* toluaI_clone = tolua_copy(tolua_S,(void*)&toluaI_ret,sizeof(GamePos2d));#endif tolua_pushusertype(tolua_S,tolua_doclone(tolua_S,toluaI_clone,tolua_tag(tolua_S,"GamePos2d")),tolua_tag(tolua_S,"GamePos2d")); } } } return 1;tolua_lerror: tolua_error(tolua_S,"#ferror in function ''normalized''."); return 0;}/* Open function */int tolua_gp2d_open (lua_State* tolua_S){ tolua_open(tolua_S); toluaI_reg_types(tolua_S); tolua_cclass(tolua_S,"GamePos2d",""); tolua_function(tolua_S,"GamePos2d","new",toluaI_gp2d_GamePos2d_new00); tolua_function(tolua_S,"GamePos2d","delete",toluaI_gp2d_GamePos2d_delete00); tolua_function(tolua_S,"GamePos2d","tolua_raw_delete",tolua_GamePos2d_tolua_raw_delete); tolua_function(tolua_S,"GamePos2d","normalized",toluaI_gp2d_GamePos2d_normalized00); return 1;}/* Close function */void tolua_gp2d_close (lua_State* tolua_S){ lua_pushnil(tolua_S); lua_setglobal(tolua_S,"GamePos2d");}
I had a tolua problem a while back, but it was being caused by the lua-classes part of ToLua. There was a patch I got from the mailing list. I don''t have it available right now though.

I''d suggest posting to the mailing list?
It''s a very responsive group.

oh, and follow up here if you figure it out?

This topic is closed to new replies.

Advertisement