lua-users home
lua-l archive

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

> 1. In pmain() function garbage collector is stopped before
> luaL_openlibs() call, and restarted afterwards:
>   lua_gc(L, LUA_GCSTOP, 0);  /* stop collector during initialization */
>   luaL_openlibs(L);  /* open libraries */
>   lua_gc(L, LUA_GCRESTART, 0);
> 2. In docall() function garbage collecgtion is forced on pcall error:
>   /* force a complete garbage collection in case of errors */
>   if (status != 0) lua_gc(L, LUA_GCCOLLECT, 0);
> Quick googling up didn't bring the answer, so, the question is:
> What is the motivation for each of these cases, and when should I do
> the same? :-)

The first use is to reduce the GC overhead when creating large number of
objects that are not garbage. The second is to release resources (e.g.,
file handlers) that should be released by the program if there were no

-- Roberto