[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: LuaJIT and keeping objects alive
- From: Jim Pryor <lists+lua@...>
- Date: Wed, 25 Nov 2009 13:56:02 -0500
I haven't started using LuaJIT yet, but I have been working with some
design patterns that I wonder whether could still be relied on there.
For instance, if I do this:
local bar
local function foo()
local U = newproxy(true)
getmetatable(U).__gc = function(self) print "goodbye world" end
return bar(U)
end
function bar(U)
...lots of processing that might force a garbage-collection...
...nowhere here do we do anything with U...
end
In straight Lua, U will still be alive during the execution of bar, so
it won't be gc'd until after bar returns. Could that still be relied on
in LuaJIT? Or might the JIT compiler see that U is never touched inside bar,
and optimize foo's tail-call in such a way that U is no longer
referenced by anybody once control switches to bar?
I realize there are work-arounds. For instance, one could change foo so
that the call to bar was no longer a tail-call. Or one could keep U
alive during bar's execution in another way (what I ended up doing). I
just suspected this might be something I'd need to attend to when using
n optimizing compiler.
--
Profjim
profjim@jimpryor.net