> I was wondering if the same idea could not be transposed to Lua, by considering a value as ‘published’ if added to a table, used as an up-value or returned by a function. In other words, could a collectable value only used in one (or several) local variable(s) be released immediately at the end of the syntactic scope of these variables if not ‘published’?
This has been discussed from a somewhat different angle for a couple of times within a few recent months. The different angle was the desire to have local objects finalized upon leaving their syntactical scope because some of those objects could hold some expensive resources, such as DB connections. You are essentially proposing the same thing, albeit with a different way to determine when finalization is feasible.
It would be nice to hear from Lua's fathers what (and whether) we could expect with respect to deterministic finalization.