auto reference counting with iOS 5.0

iOS 5.0 introduced us to ARC for mobile. this is a major change (advantage) in the way developers  work. what was once a source for memory leaks, which required diligent memory allocation and management, becomes easier and much simpler of a task, allowing developers to focus on the code.

LLVM rocks indeed.

think of it as new ‘best practices’ one should incorporate into their coding habits, while disallowing other practices:

  • no more retain, release, autorelease nor dealloc
  • no more custom retain nor release method implementations
  • do not store obj pointers in C structures (use objects instead)
  • no more direct casting between objects and non objects (e.g. id and void*)
  • you are done with NSAutoreleasePool. use @autoreleasepool keyword to mark the block in curlies.

what ARC should encourage you to do is start thinking about the relationship between objects and object graphs, and not so much in terms of retain/release. there is now a new lifetime qualifiers for objects, which includes zeroing weak references. the value is automatically set to nil when the object it points to is deallocated. we now have qualifiers for vars and new weak and  strong declared property attributes.

apple is providing developers with migration tools which are build into xcode: .

switching to ARC means neglecting support for iOS >5.0.
add custom containers to the mix, much more control over customizing UIKit elements, storyboards, tableView’s new flexibility and much more.

happy coding.

Leave a Reply

Your email address will not be published.