[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: When will userdate be freed/gced?
- From: Andrew Gierth <andrew@...>
- Date: Sun, 07 Apr 2019 13:07:38 +0100
>>>>> "Marc" == Marc Balmer <email@example.com> writes:
Marc> In a C function that is called from Lua, I use the following idiom:
Marc> char *s;
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.