do local list = setmetatable({}, { __mode = "v" }) local function RunInCoroutine(func) local coro, handle = coroutine.create(func), {} list[coro] = handle coroutine.resume(coro, handle) end function CoroTest() RunInCoroutine(function(handle) print("This one will be collected:", handle) end) RunInCoroutine(function(handle) print("This one WON'T be collected:", handle); error(1) end) RunInCoroutine(function(handle) print("This one will be collected too:", handle) end) collectgarbage() for coro, handle in pairs(list) do print("Still alive:", handle, "Coroutine status:", coroutine.status(coro)) end end end CoroTest()