Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does ARC work for iOS 4.0+ only?

What is the technical reason for ARC to be supported by iOS 4.0 and above only?

It is my understanding that it is a compiler feature, which merely inserts memory management related code automatically instead of requiring the developer to do so. From what I read the calls themselves remain the same - at least that's what Apples Transitioning to ARC Guide implies.

As such, it should not involve features that have not been present in previous versions of iOS, and indeed ARC does work with iOS 4.0 despite having been introduced later.

I'm asking this question out of curiosity and don't actually need to make ARC work with iOS 3.x.

like image 221
Toastor Avatar asked Mar 06 '12 10:03

Toastor


People also ask

How does ARC work in IOS?

How ARC Works. Every time you create a new instance of a class, ARC allocates a chunk of memory to store information about that instance. This memory holds information about the type of the instance, together with the values of any stored properties associated with that instance.

What is memory management handled on IOS?

Memory management is the programming discipline of managing the life cycles of objects and freeing them when they are no longer needed. Managing object memory is a matter of performance; if an application doesn't free unneeded objects, its memory footprint grows and performance suffers.

What does a retain count represent in ARC?

Retain Count represents number of owners for a particular object. It is zero till object does not have any owners. Increase in one ownership claim will cause retain count to increase by 1 and decrease will cause it to decrement by 1. Example: - Class A object is created using alloc/init and retain count is 1.


1 Answers

It is for the same reason that automatic reference counting only supports 64-bit Snow Leopard as a minimum deployment target: ARC support requires certain features present only in a new enough version of the modern runtime. That modern runtime was introduced with iOS 4.0, so older iOS versions lack the runtime capable of handling some of the things required technically by ARC. If it were just keyed to OS versions, 32-bit Snow Leopard applications would be supported as well, but only the 64-bit runtime is the modern one there.

If you watch Apple's presentations from WWDC 2011, particularly the "Objective-C Advancements In-Depth," you'll see that a number of under-the-hood improvements have been made to speed up the retain / release process, as well as things like the faster @autoreleasepool. There's an entire section on runtime support in the LLVM ARC specification. These improvements require more than just compiler support.

We already had to use the modern runtime for features like automatic synthesis of instance variables (as explained in Apple's documentation), so this isn't a terrible surprise.

Even iOS 4.0 as a target lacks support for weak references, so there are clearly technical issues at play here. This isn't just a marketing strategy to drive developers to the newer versions, as has been asserted by others.

like image 59
Brad Larson Avatar answered Oct 16 '22 23:10

Brad Larson