lua-users home
lua-l archive

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


Two ideas:

1) You could explicitly lua_unref your table to clean it up.
2) Instead of storing your table directly in the registry, you
could store it in a weakly-valued subtable of the registry.  That way,
when the last reference outside of the registry table goes away, your
table is collectable.

-Rob Hoelz

On Tue, 9 Jun 2009 12:43:38 -0700
"Martin, Marcus" <mamartin@ea.com> wrote:

> 
> I have a lua table that I have added to the registry. I added some
> user date to the table and removed the data from the local stack.
> 
>     lua_newtable(luaState);
>     lua_rawseti(luaState, LUA_REGISTRYINDEX, index);
>     lua_rawgeti(luaState, LUA_REGISTRYINDEX, index);
>     lua_pushlightuserdata(luaState, this);
>     lua_setfield(luaState, 1, "userdata");
>     lua_pop(luaState, 1);
> 
> I then use the data in my program for a while. Eventually I am done,
> and want to remove the table and the user data from the Lua state by
> indicating they can be garbage collected. Is this all I need to do?
> Or do I need some special steps because of the user data in the
> table? luaL_unref(LUA_REGISTRYINDEX, index);
> 
> 
> Marcus
> 

Attachment: signature.asc
Description: PGP signature