On May 24, 2014, at 2:34 PM, Jamie Ojomoh <jamie.ojo...@gmail.com> wrote:

> In the example, everything inside the autoreleasepool block will be
> released as soon as the block ends, so it's necessary to declare the return
> value outside the block.

No, in general ARC understands that the return value needs to keep a reference, 
so it’s safe to put the return statement inside the autorelease block. In your 
specific example, returnString was allocated before you created your 
autorelease pool, so that pool won’t release it anyway. Also, you allocated 
returnString using an alloc/init sequence so it’s not in an autorelease pool at 
all.

(In your example I don’t think the autorelease pool is doing anything at all, 
since there are no calls in that block that would cause any object to be 
autoreleased.)

> When does returnString get released?  Does it get automatically released as
> soon as the method ends and the value has been passed into whatever
> container was waiting for it?

 I believe ARC will take care of autoreleasing it at the point where it’s 
returned.

Apple’s docs specifically recommend that you _don’t_ worry about when objects 
are being retained or released. ARC basically takes care of it for you, so most 
of the time you can pretend that the app is garbage-collected and ignore 
retain/release entirely. Instead, consider where you need strong or weak 
references to objects; this is mostly a concern when declaring instance 
variables.

—Jens

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

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