On Apr 22, 2014, at 15:18 , Dave <d...@looktowindward.com> wrote:

> I assumed that ARC would release myImage on each interation of the loop, 
> however, this seems not to be the case

The ‘myImage’ variable gives up *ownership* of the previous image object when 
you create a new one in the loop, but whether that leads to a deallocation of 
the object is an implementation detail. If it’s autoreleased anywhere in its 
[short] lifetime, the image object will linger in the autorelease pool until 
the pool is drained, as Keary said.

If you want to avoid autoreleases, you should ensure that the image is returned 
from the download method with +1 ownership semantics. As far as that method is 
concerned, you can do this by changing its name to start with ‘new…’, or 
decorate its declaration with ‘__attribute__((ns_returns_retained))’. You 
would, of course, have to ensure that the download method and the methods it 
calls don’t do anything else that’s likely to retain/autorelease the image.

This sort of thing is a bit messy because it relies on presumed (but partially 
documented) knowledge of the ARC implementation. It’s more robust and 
straightforward to do what Keary says. However, if you really wanted to avoid 
autoreleases completely, there are ARC strategies that can help.

_______________________________________________

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