lua-users home
lua-l archive

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


The reference solution runs into the same problem as weak tables with
creating cycles that won't be garbage collected.

Mark

on 9/3/03 10:47 AM, Virgil Smith at virgil@nomadics.com wrote:

> Sounds like a good use for references.
> Just put the "attached" values in a table in the registry and keep a
> reference in the userdata.
> In the userdata's GC method, unlock the reference.
> 
> The "tricky" bit is to make GC work correctly.  As a "poor" solution you
> could write a "lua_freeuserdatavalues(L, index_of_userdata)" and require
> that userdata GC methods call this function.  As a "good" solution you could
> write a new version of setmetatable that checked the GC method and if it was
> not already "fixed" then "fix" it to reference a function that retrieves the
> original GC function from somewhere (probably from the metatable or the
> "associated values" table), calls that function, and then "frees" the
> associated data values.
> 
> <Definitions of "poor" and "good" are purely my opinion, you have to decide
> if "mucking" with the metatables is better than relying on the userdata GC
> methods manually calling something.>