Mailing Lists: Apple Mailing Lists
Image of Mac OS face in stamp
Re: Why does ARC retain method arguments even with full optimization?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Why does ARC retain method arguments even with full optimization?



On Nov 4, 2011, at 6:00 AM, Hamish Allan wrote:

> On 4 November 2011 12:43, Frank Illenberger <email@hidden> wrote:
>
>> does anybody know why when compiling with ARC, method arguments get retained? This happens even with full compiler optimizations enabled.
>> This is contradicts the ARC specification ( http://clang.llvm.org/docs/AutomaticReferenceCounting.html#optimization ) which reads:
>>
>>> [snip] For example, if a retain and release immediately bracket a call, the optimizer can delete the retain and release [snip]
>
> Perhaps the retain occurs *after* the call, before the NSLog?

That is correct. When the compiler doesn't know anything about the memory management behavior of a function or method (and this happens a lot), then the compiler must assume:

1) That the function or method might completely rearrange or replace the entire object graph of the application (it probably won't, but it could).
2) That the caller might be manual reference counted code, and therefore the lifetime of passed in parameters is not realistically knowable.

Given #1 and #2; and given that ARC *must* never allow an object to be prematurely deallocated, then these two assumptions force the compiler to retain passed in objects more often than not.

davez _______________________________________________
Do not post admin requests to the list. They will be ignored.
Objc-language mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Why does ARC retain method arguments even with full optimization? (From: Frank Illenberger <email@hidden>)
 >Re: Why does ARC retain method arguments even with full optimization? (From: Hamish Allan <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2011 Apple Inc. All rights reserved.