local a = {}
local b = {}
setmetatable(a, b)
--这个 table 中的 vaules 就是 weak
b.__mode = "k" -- now 'a' has weak keys
local t1 = {}
local t2 = {} -- creates first key
a[t1] = 0
a[t2] = 1
--t2 is empty,can be gc
t2 = {}
collectgarbage()
for k, v in pairs(a)
do print(v)
end
0
lua weak表与gc
最新推荐文章于 2024-06-19 20:16:19 发布