On Fri Dec 30 06:31:34 2011, dolmen wrote: > Le Sam. Déc. 24 18:55:03 2011, sprout a écrit : > > > > I think this is a bug, in that mentioning a variable in a sub shouldnât > > change whether $x has the only reference after â$x = sub{}â. > > Well, it does. > > In my use case, I use weaken on closures to break circular references > (an object method that stores as a member a closure that references > $self, and I want the closure to disappear when $self is not anymore > referenced). This is quite common when working with AnyEvent. > > The bug I had in my code was that I did use weaken "as usual" on the > sub. So my mistake was to do a weaken on something which was not a > closure: there was no circular reference problem in the first place. I > was trying to use 'weaken' to workaround a problem which didn't exist. > > To avoid such mistakes in the future, would it be possible to detect and > report such cases of usage of weaken on non-closure subs? But holding a weak reference to a non-closure sub is not necessarily a bug. Weak references are not just for breaking circularities, you know. :-) Sometimes they are useful for maintaining mappings between references. See, e.g., Tie::RefHash::Weak. > > > It also causes the blessing bug in ticket #3306. > > Thanks for that reference. I submitted an idea on how to fix that one too. > > -- > Olivier -- Father Chrysostomos --- via perlbug: queue: perl5 status: open https://rt.perl.org:443/rt3/Ticket/Display.html?id=106864Thread Previous