lua-users home
lua-l archive

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

On Apr 11, 2007, at 9:49 AM, Luiz Henrique de Figueiredo wrote:

On the downside: the registry table can never shrink. Once you use a
million references those 12-16 million bytes will stay allocated until
the lua_State object is destroyed.

Not if you use luaL_unref to release references.

How's this code shrinking the array? The objects referred to will be recycled if you use luaL_unref and it's the only reference, but luaL_unref builds a linked list out of recycled indices right inside the registry array, so the array cannot shrink, as far as I can tell.

LUALIB_API void luaL_unref (lua_State *L, int t, int ref) {
  if (ref >= 0) {
    t = abs_index(L, t);
    lua_rawgeti(L, t, FREELIST_REF);
    lua_rawseti(L, t, ref);  /* t[ref] = t[FREELIST_REF] */
    lua_pushinteger(L, ref);
    lua_rawseti(L, t, FREELIST_REF);  /* t[FREELIST_REF] = ref */

Gé Weijers