[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Unmark for finalization and stuff
- From: Kai Mismahl <kaimismahl@...>
- Date: Mon, 11 Aug 2014 22:53:15 +0200
Objects marked for finalization can not be umarked (e.g. by setting a metatable without __gc). Since marking for finalization is quite explicit through a call to setmetatable, couldn't the same code in the Lua source remove that mark?
t = setmetatable({}, {__gc = false}) -- enables finalization (even with false, which is against that one Lua idiom IMO (nil and false vs. the rest))
setmetatable(t, {}) -- should disable finalization IMO
getmetatable(t).__gc = function () assert(false, "finalizing") end -- sneak a finalizer in
t = nil collectgarbage() -- finalizing!
--
During my trials on that part I stumbled on another thing. If setmetatable is called without a second argument it throws. I thought another Lua idiom is to assume nil for implicit arguments. Is that a bug or am I missing something?
setmetatable{}
--
I fear I should have divided this into different mails, but then again I got all these questions while pondering about the GC, well...
While unreachable weak values (and the associated keys) are removed before finalization, this is not done in ephemeron tables (when the key got unreachable), although those values are effectively weak, too.
That also makes ephemeron tables and mode kv tables only subtly different (for me).
Personally I think those nuances about what gets removed when and why that is so is one of the more confusing parts of Lua : (
--
I found other bits, like multiple finalization, already fixed in the 5.3 work versions. So I am quite estatic about the next Lua and especially PiL4 : D