Possible Duplicate:
Objective-C: With ARC, what's better? alloc or autorelease initializers?
Does ARC automatically turn the autoreleased versions of class initializers into the appropriate non-autorelased versions, or are they still technically being autoreleased?
I don’t want to keep memory around any longer than it’s absolutely required, so I’ve gotten in the habit of using alloc/init in almost all circumstances. Now in ARC, I’m wondering if I can just start using the “autorelease” initializers and expect them to act like a non-autorelased versions would behave…
Does anyone have any documentation on where I can find out what happens to autoreleased methods under ARC?
When you get an autoreleased object, ARC will manage to avoid the autorelease pool, as long as both your code and the called method/function are compiled with ARC.
ARC adds a call to
objc_retainAutoreleasedReturnValuein your code and a call toobjc_autoreleaseReturnValuein the called function/method. At runtime whenobjc_autoreleaseReturnValuesees that the returned value will be retained byobjc_retainAutoreleaseReturnValue, it doesn’t autorelease the object and sets a flag to tellobjc_retainAutoreleaseReturnValuenot to retain the object. Thus you get no (perceptible) extra cost for using a convenient creation method rather thatalloc/init.For more information about that mechanism, you may read How does objc_retainAutoreleasedReturnValue work? by Matt Galloway.
In conclusion, just use the method you prefer, Apple engineers will ensure it runs fast.