local t = {}
setmetatable(t, {__mode="k"}) -- t的key是弱引用,一旦其他地方没有了对key的引用,那么t里的这个字段也会被删除

local key1 = {name="key1"}
t[key1] = 1

key1 = nil

collectgarbage() -- 强制进行一次垃圾回收

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