[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Problem with circular refrence and garbage collection
- From: <malobu@...>
- Date: Sat, 10 Jan 2009 0:05:27 -0800
I am creating a Lua api for a gui toolkit i am working on and have run
into a snag with garbage collection not happening when there is a
circular refrence.
--After this chunk is run there is no refrence to frame, it is collected
eventually the problem is col and the button that is attached to it is
never collected
local frame = cwl:createFrame("Hello World")
--attachTo will create a refrence to col in frame, which goes away when
the frame is collected
local col = cwl:createColumn():attachTo(frame)
--attachTo will create a refrence to button in col
local button = cwl:createButton():attachTo(col)
--the function is refrenced by the button to lock it into existence
until the button is collected.
--but when I create this closure with col as an upvalue, it locks col
into existence, when frame is collected, col is not becuase of this
refrence.
button:onEvent("click", function(b) col:selectRow(i) end)