[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Userdata and memory management
- From: Rob Hoelz <rob@...>
- Date: Tue, 9 Jun 2009 14:52:55 -0500
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.
On Tue, 9 Jun 2009 12:43:38 -0700
"Martin, Marcus" <firstname.lastname@example.org> 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_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);
Description: PGP signature