[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Issues with the garbage collector
- From: "Wesley Smith" <wesley.hoke@...>
- Date: Thu, 30 Nov 2006 13:52:26 -0800
As a quick follow up just to be more precise, what's the difference
--------------script global scope
myvar = 1
local myvar2 = 1
I load this script with a loadstring and pcall and everything is fine.
Now, I have in C a callback mechanism that does a getglobal on cb and
passes in some args. In the process, I create a table, so eventually
the GC gets called. When that happens, myvar2 will disappear and
obviously myvar won't. It was my (apparently wrong) understanding
that local values at global scope would persist at the global level.
However, this isn't the case. Where do they exist and to what extent
do they exist?
On 11/30/06, Wesley Smith <firstname.lastname@example.org> wrote:
print("cb: " .. tostring(event))
for k, v in pairs(event) do
print("\t" .. tostring(v))
print(table.concat(event.args, ", "))
local listener = jit.listener("listen", "cb")
local xfade = jit.new("jit.xfade")
In the above script, I have 2 userdata variables. The "listener"
object registers a Lua function as a callback from another part of the
app the script is embedded in. In the C function that passes data to
the Lua callback function, I'm allocating a small table, "event", and
passing it to the callback function. After a certain period of time,
the garbage collector gets called and calls both userdata __gc
functions, freeing them.
My question is how does the GC decide what to free? I don't think
either listener or xfade should be deleted because they're still valid
variables. What is the metric being used by Lua to decide what gets