lua weak表与gc

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

猜你喜欢

转载自xiangjie88.iteye.com/blog/2401204
今日推荐