[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Garbage Collection Breaks Next
- From: Roberto Ierusalimschy <roberto@...>
- Date: Tue, 13 Oct 2020 11:10:39 -0300
> Seems like globals are traversed first, so using a global table this problem
> can happen in the main thread.
>
> t = {}
> t["no" .. "ref1"] = 1
> t["no" .. "ref2"] = 2
>
> for k, v in pairs(t) do
> t[k] = nil
> print(k, v)
> collectgarbage("collect")
> end
The coroutine-based version seems more stable. This example does not
seem to work (that is, does not "not work" :-) when inserted inside a
larger test file, with many other globals. I guess it depends on the
order that items are visited in the global table. Inside threads (using
local variables), the order is more predictable.
-- Roberto