1.附上代码(1)
local a = {}
local b = { __mode = "k" }
setmetatable(a,b)
local key = {}
a[key] = 1
local key = {}
a[key] = 2
collectgarbage()
for i ,v in pairs(a) do
print("xxxxx",i,v)
end
输出结果:
Lua print: xxxxx table: 00D5D930 1
Lua print: xxxxx table: 00D5D978 2
为什么垃圾回收没有成功?
2.附上代码(2)
local a = {}
local b = { __mode = "k" }
setmetatable(a,b)
l key = {}
a[key] = 1
key = {}
a[key] = 2
collectgarbage()
for i ,v in pairs(a) do
print("xxxxx",i,v)
end
输出结果:
Lua print: xxxxx table: 00D5DA30 2
垃圾回收却成功了,弄不明白为什么了?那位大神帮忙分析为什么?
还有这个lua垃圾回收的原理。谢谢