What if the value is not a table? --- tab = {} setmetatable(tab, {__mode = 'v'})
r = function() end tab['key'] = r
r = nil collectgarbage() —
When ‘r' is collected, how could ‘tab’ know that?
Thanks. /hz
Am 03.09.2018 um 17:18 schrieb Zhao Han: Hi, All,
For a weak table, is it possible to use some meta table tricks to track the changes of the table?
e.g. when a key or value get collected, print a message.
Best Regards, /hz
You could try to use the __gc field at a metatable at the objects that are going to get collected -- Oliver
|