On Apr 25, 2013, at 1:20 AM, Oleg Krupnov <[email protected]> wrote:
> This breaks encapsulation of objects with block properties (e.g.
> MyAnimation.completionBlock)
I understand the problem you're describing (and yes, I've had a couple of
memory leaks resulting from it) but I don't understand how you think it's
breaking encapsulation.
> It seems to me that it's much better to drop the convenience of blocks
> in favor of safety and full control of retain/assign relationships
> between my objects.
It's a subjective decision, but for what it's worth, I disagree. Blocks are so
useful that it's not worth giving them up. In any case, you're talking about
only one use of blocks — as a way to tell an object an action to perform later,
a replacement for delegates or target/action pairs. There are plenty of other
good uses for blocks that don't have these issues.
In my code, most of the places I use a block as an onXXX property value it's
going to be called exactly once. What I do then is, in the caller, set the
corresponding _onXXX ivar to nil after calling through it, to break cycles.
- (void) xxxHappened {
if (_onXXX) {
_onXXX();
_onXXX = nil;
}
}
—Jens
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________ Cocoa-dev mailing list ([email protected]) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [email protected]
