[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Callbacks, upvalues and memory management
- From: Gregory Bonik <gregory@...>
- Date: Sat, 30 Jul 2011 13:03:29 +0400
Valeriy E. Ushakov wrote:
> Can you break the dependency by making on_click pass the object to the
> handler?
>
> b:on_click(function(b) b:some_method() end)
>
Yes, but it is only a partial solution. Consider a bit more complicated
example:
local a = Button()
local b = Button()
a:on_click(function() b:some_method() end)
b:on_click(function() a:some_method() end)
Now `a' holds a reference (via "refs" table) to the first anonymous
function, which in turn refers to `b', which holds a reference to the
second anonymous function, which finally refers to `a'. Here we get a
cycle of length 4 instead of 2.
-- Gregory Bonik