problem with luaL_newmetatable

dolphindolphin Join Date: 2010-04-23 Member: 71502Members
I have a problem that is causing me to run out of memory when I have Decoda attached. It looks like LuaInject is calling <a href="" target="_blank">luaL_ref</a> when I call <a href="" target="_blank">luaL_newmetatable</a>, but never calling <a href="" target="_blank">luaL_unref</a>. Each call to luaL_newmetatable is adding a new reference to the metatable to the registry. This causes the registry table to grow unbounded.

This feels like a bug in handling luaL_newmetatable. According to the docs, luaL_newmetatable doesn't always create a new metatable, it will return an existing one. I <i>think</i> I can work around this by using <a href="" target="_blank">luaL_getmetatable</a> then checking for nil then calling luaL_newmetatable, but I hesitate to add in strange looking code just to make Decoda work. If you have any other suggestions please let me know.


  • dolphindolphin Join Date: 2010-04-23 Member: 71502Members
    I have been able to work around the problem with the following code:

    <!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->inline int newmetatable(lua_State* L, const char* name)
        if(lua_isnil(L, -1))
            lua_pop(L, 1);
            return 1;
        return 0;

    #define luaL_newmetatable(L,name) newmetatable(L,name)<!--c2--></div><!--ec2-->
Sign In or Register to comment.