lua-users home
lua-l archive

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


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)