lua-users home
lua-l archive

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


>>>>> "Marc" == Marc Balmer <marc@msys.ch> writes:

 Marc> In a C  function that is called from Lua, I use the following idiom:
 Marc> char *s;
 Marc> ...
 Marc> s = lua_newuserdata(L, 128);

Notice that this pushes the Lua value onto the stack, in addition to
returning a pointer to the data block address.

While the value is on the Lua stack, it is referenced and therefore will
not be GC'd. If you drop it from the stack without storing some other
reference to the value (e.g. by putting it in a table, closure, or
uservalue), then it will be GC'd when the collector next gets around to
it. If you did store it somewhere, then it will not be GC'd until after
all such (strong) references no longer exist or are no longer reachable.

You should never try and free it explicitly.

-- 
Andrew.