On 4 February 2014 14:19, Michel Fortin <michel.fortin@michelf.ca> wrote:
On 2014-02-04 03:45:33 +0000, Manu <turkeyman@gmail.com> said:Oh, no. Beware of closures. That's a frequent problem in Objective-C ARC, even for those who understand ARC well. You have to be very careful of closures creating cycles if you use them as callbacks. For instance, you have a view that has a pointer to the model and sets a callback for the model to call when something change to update the view; that's a cycle and you need to use a weak ref to the view within the closure. Pretty common pattern.
The majority of trivial allocations don't produce cycles; closures,
strings, temporary arrays and working sets.
Ah right. Interesting.It sounds like this could be addressed easily though by the API that manages the 'event' handler. If you use a raw delegate, maybe it's a problem, but it sounds like an event-programming construct, and that usually requires an event class that can handle multiple subscribers, as soon as that exists, it's easy to hide the weak reference behind the event api...