lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


function cb(event)
	print("cb: " .. tostring(event))
	for k, v in pairs(event) do
		print(k)
		print("\t" .. tostring(v))
		print("")
	end
	
	print(table.concat(event.args, ", "))
	print(listener)
end

--userdata
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
deleted?

thanks,
wes