> On Aug 15, 2015, at 05:21, Sandy McGuffog <[email protected]> wrote:
> 
> What guarantees that the current autorelease cycle doesn’t end in the middle 
> of this code?

Because that’s how autorelease pools work.

> Actually, as I think about it, technically, the [[hostObject myArray] retain] 
> should be wrapped in some kind of lock mechanism itself to make it atomic….

Nope. If, as has already been stated, myArray is an atomic property, that is 
already taken care of for you.

>> On Aug 15, 2015, at 2:10 PM, Mike Abdullah <[email protected]> wrote:
>> 
>>> On 15 Aug 2015, at 13:07, Sandy McGuffog <[email protected]> wrote:
>>> 
>>>> On Aug 15, 2015, at 1:14 PM, Mike Abdullah <[email protected]> wrote:
>>>> 
>>>> NSArray *array = [hostObject myArray];
>>>> // run your checks, etc.
>>>> NSString *someString = [array objectAtIndex:2];
>>> 
>>> Just to be safe:
>>> 
>>> NSArray *array = [[hostObject myArray] retain];
>>> // run your checks, etc.
>>> NSString *someString = [array objectAtIndex:2];
>>> [array release];
>>> 
>>> Or whatever other way of ensuring the array isn’t dealloced out from under 
>>> you, depending on how you’re doing memory management
>> 
>> No need. The OP has stated myArray is an atomic property. It’s guaranteed 
>> not to go away until the end of the current autorelease pool.
>> 
>> If the above code did actually add some protection, it would mean the first 
>> line of code had a race condition in it where you might not be able to 
>> retain in time. You’d just be hiding the problem and making it less likely, 
>> rather than actually fixing it.
> 
> 
> _______________________________________________
> 
> 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/clarkcox3%40gmail.com
> 
> This email sent to [email protected]


_______________________________________________

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]

Reply via email to