lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


> Usually, the garbage collector does not depend on lua_pcall to run. Can you be more specific about your problem?

If I comment out the LUA_GCCOLLECT in the code below memory usage will grow. If the test() function doesn't cause an error memory will stay static without LUA_GCCOLLECT.

#include <lua/lauxlib.h>
#include <lua/lualib.h>
#include <lua/lua.h>

static const char* script = "function test() "
                            "  bob.joe.larry = 23 "
                            "end";

void check(lua_State* L, int ret)
{
  if( ret ) 
  {
    printf(lua_tostring(L, -1));
    lua_pop(L, 1);
    // if I comment out this line memory use will grow without bounds
    lua_gc(L, LUA_GCCOLLECT, 0);
  }
}

int main( int argc, char** argv )
{
  lua_State* L = luaL_newstate();
  luaL_openlibs(L);
  check(L, luaL_dostring(L, script));
  while(true)
  {
    lua_getglobal(L, "test");
    check(L, lua_pcall(L, 0, 0, 0));
  }
}