And of course the second I hit Send I realized the do {} idea doesn't work.  
Imagine if it was some variable other than self that you might *deliberately* 
use to indicate when the loop should terminate.

--Andy

--Andy

> On Jul 18, 2014, at 10:07 AM, Andy Lee <ag...@mac.com> wrote:
> 
> You could even eliminate the (admittedly negligible) cost of setting 
> keepAlive = nil by changing the if(keepAlive) to if(!keepAlive).
> 
> Along the lines of avoiding a message send, I wonder if this would work:
> 
> do {
>    // ...
> } while (!self);
> 
> --Andy
> 
>> On Jul 18, 2014, at 9:41 AM, Gerd Knops <gerti-cocoa...@bitart.com> wrote:
>> 
>> That's similar to what I have used. Initially it started out simply as
>> 
>>   id    keepAlive=self;
>>   ...
>>   keepAlive=nil;
>> 
>> but a few Xcode versions ago the static analyzer started complaining that it 
>> wasn't really doing anything. So that last line became
>> 
>>   if(keepAlive) { keepAlive=nil; }
>> 
>> which shut up the analyzer. [keepAlive self]; like Andy suggests would 
>> probably work just as well, though probably a tad more expensive as a method 
>> call is involved.
>> 
>> Gerd
>> 
>>>> On Jul 17, 2014, at 11:23 PM, Andy Lee <ag...@mac.com> wrote:
>>>> 
>>>> On Jul 17, 2014, at 11:01 PM, Jens Alfke <j...@mooseyard.com> 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 (Cocoa-dev@lists.apple.com)
>>> 
>>> 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/gerti-cocoadev%40bitart.com
>>> 
>>> This email sent to gerti-cocoa...@bitart.com
>> 

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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 arch...@mail-archive.com

Reply via email to