lua weak table and gc

local a = {}
local b = {}
setmetatable(a, b)
--The vaules in this table are 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

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326486708&siteId=291194637