lua-users home
lua-l archive

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


> If U is both a key and value then it follows the weak-key rule,
> finalize then remove table pair?
> 
> 	t = setmetatable({},{__mode='kv'})
> 	U = ... some userdata with a __gc
> 	t[U] = U
> 	U=nil
> 	collectgarbage()
> 	-- U will be in t until after __gc is called?

The key follows the key rule, the value follows the value rule. Like
with any pair, if any of them is removed, the entire pair is
removed. So, in your example, that entry would be removed. (That is,
the U in t[U] is not being collected yet, but the U in "= U" is, so
the pair is removed.)

-- Roberto