We use cookies on this site to enhance your user experience

Weak Keys

Weak Keys

local t, key
t = {}
setmetatable(t, {__mode = "k"}) -- now a has weak keys

key = {}               -- creates first key
t[key] = 1

key = {}               -- creates second key
t[key] = 2

-- forces a garbage collection cycle
collectgarbage()       

for k, v in pairs(t) do 
	print(v) 
end