Re: How do I temporary retain self, under ARC?
Re: How do I temporary retain self, under ARC?
- Subject: Re: How do I temporary retain self, under ARC?
- From: Andy Lee <email@hidden>
- Date: Fri, 18 Jul 2014 00:23:55 -0400
On Jul 17, 2014, at 11:01 PM, Jens Alfke <email@hidden> wrote:
> Once I’ve identified such a bug, the fix is easy: put a [[self retain] autorelease] at the top of the method. Except now I’m using ARC, and I can’t find a simple way of doing it. I tried adding
> __unused id retainedSelf = self;
> but the optimizer recognizes that retainedSelf isn’t used and strips it out, making this a no-op. The only thing I’ve found that works is
> CFRetain((__bridge CFTypeRef)self);
> at the top of the method, and a corresponding CFRelease at the end, but this is pretty ugly and could cause leaks if the method returns early.
How about
id retainedSelf = self;
at the beginning and
[retainedSelf self];
at the end?
--Andy
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden