On Aug 6, 2011, at 6:57 PM, Thomas Wetmore wrote:

> It may look odd to use an object that has been just released, but there is 
> nothing wrong in this case, and no assumptions are needed here. As soon as 
> the object has been added to the array it has been safely retained on the 
> same thread by well-understood and well-documented rules, and it should be 
> released as soon thereafter as is practical. I too don't like the way this 
> code feels, but moving the release to the end has no effect other than making 
> some of us possibly feel good. For those who feel best when memory is 
> released as soon as it is possible to do so, this code is fine. For however 
> laudable it is to write comfortable code one must decide for oneself where to 
> put the release.

I disagree. It may *work* in this case, but that is because of the 
implementation detail that employeeController puts the same object into its 
array instead of copying it, and then on the implementation detail that NSArray 
retains its contents instead of copying them, and the implementation detail 
that employeeController isn’t using a custom non-retaining CFArray or 
something. Any of that stuff changes, you get a crash.

There’s no real reason to release the object before you’re done with it, so 
just don’t do that. Keep the object while you need it, and then release it 
after you’re done with it.

Charles_______________________________________________

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to