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.
> 
> [...]

Thanks for the feedback. We can reproduce the problem in pure Lua:

----------------------------------------------------------
local code = "function test()\n  bob.joe.larry = 23\n end"

load(code)()

for i = 1, math.huge do
  pcall(test)
  io.write(collectgarbage'count'*1024, "\n")
end
----------------------------------------------------------

It is a very peculiar case. The entire loop does not create any object
at all, except for the error messages. The error message are somewhat
long, so Lua 5.2.1 does not internalize it, creating a new copy each
iteration. Lua does check the collector when it creates error messages,
and so the collector does not get a chance to run.

The problem is lightly related to this:

  http://lua-users.org/lists/lua-l/2012-08/msg00149.html

The error causes Lua to skip that check, too. Replacing that
check solves both problems:

*** ldo.c:
313a314
>       luaC_checkGC(L);  /* stack grow uses memory */
340a342
>       luaC_checkGC(L);  /* stack grow uses memory */
396d397
<   luaC_checkGC(L);

-- Roberto