[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Coroutines with overflown stacks seem to confuse GC; is this expected?
- From: Roberto Ierusalimschy <roberto@...>
- Date: Mon, 24 Jul 2023 13:47:10 -0300
> After a stack overflow in a coroutine, the GC appears not to clean up
> its stack. This seems to happen at least in Lua 5.1.5 and one built
> from Git commit ea39042e13645f63713425c05cc9ee4cfdcf0a40 (5.4.6+)
> (Debian amd64).
This is expected behavior. After an error in a coroutine, you can still
inspect its stack (e.g., to make a trace), so the stack cannot be
cleared. Once the coroutine itself becomes garbage, then its stack
can be collected:
--------------------------------------
local depth=tonumber((...)) or 500000
local function recurse(n)
if n > 0 then
recurse(n-1)
end
end
local thread = coroutine.create(function (n) recurse(n);
coroutine.yield("completed") end)
collectgarbage("collect")
print("start",coroutine.resume(thread, depth))
print(coroutine.status(thread))
thread = nil -- <<< ADDED
collectgarbage("collect")
print(i, collectgarbage("count")*1024)
--------------------------------------
-- Roberto