Remember Memory

The iOS does not store “changeable” memory (such as object data) on disk to free space and then read it back in later when needed. This means that running out of memory is easy, and you should use automatic reference counting (ARC) to make the most of the memory available to you. All you have to do is follow the rules:

check.png Rule 1: Do not send retain, release, or autorelease messages.

check.png Rule 2: Do not store object pointers in C structures.

check.png Rule 3: Inform the compiler about ownership when using Core Foundation–style objects.

check.png Rule 4: Use the @autoreleasepool keyword to mark the start of an autorelease block.

check.png Rule 5: Follow the naming conventions.

If you follow the rules, all you have to worry about is the retain cycle. This cycle occurs when one object has a back pointer to the object that creates it, either directly or through a chain of other objects, each with a strong reference to the next leading back to the first. Use the weak lifetime qualifiers for objects and the weak ...

Get iPad Application Development For Dummies, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.