Пожалуйста, следуйте моим входные комментарии (с использованием Lua 5.3.2 на JDoodle):Что делает сборщик мусора, когда он собирает мертвый объект?
local table = {};
local weakvalues = setmetatable(
{
table
},
{
-- Let weakvalues values
-- be weak, so that they fade when dead objects are g-c.
__mode = 'v'
});
table = _;
-- Now the previously ref. table is unreachable
-- since there are no other references, I think so...
-- Sychronously wait this loop statements
-- in order to execute a next statement (maybe the
-- garbage-collector would have collected the unreachable table above
-- while this loop executes).
for i = 1, 5e7 do end
-- Expected to log 0, but it logs 1. Is the unreachable table
-- still reachable?
print(#weakvalues);
Я думал таблицу в table
удалит weakvalues[1]
после назначения table
с nil
.
'v' - значение. но в вашем случае вам нужно 'k' я думаю – moteus
@moteus' 'k'' для слабых клавиш ... – Hydro
Извините. Вы правы – moteus