7 iOS Tips to Help you Avoid Common Memory Mistakes

Apple Memory Management

There is no argument to be had about whether ARC is beneficial. The reduction of boiler-plate memory code, is alone, enough to justify its use. The elimination of issues resulting from objects being incorrectly retained or released also saves developers untold hours debugging weird memory management issues.

However much ARC has simplified matters, issues will still arise if memory management is not adequately understood. These issues commonly fall into two categories, retain cycles and accessing released memory.


The following tips may help developers avoid common mistakes. Tips 1, 2, 3 and 4 deal with retain cycles while 5, 6 and 7 deal with accessing released memory.

Avoid Retain Cycles

TIP ONE: Do Not Retain Delegates. Use a Weak Lifetime Qualifier.

TIP TWO: Beware of Accessing Block Owners within a Block.

TIP THREE: Do Not Retain IBOutlets unless Tip Five applies. Use a Weak Lifetime Qualifier.

TIP FOUR: Do Not Retain Subviews. Use a Weak Lifetime Qualifier.

Avoid Accessing Released Items

TIP FIVE:  Do Retain Top Level IBOutlets (but NOT the Main View or Subviews). Use a Strong Lifetime Qualifier.

TIP SIX: Do Not Access IBOutlets Unless the View Controller is Currently at the Top of the Stack

TIP SEVEN: Copy Member Blocks.

Memory management is a complex area and it is easy to make mistakes which are difficult to debug and which suck up time. If there is one area to invest time understanding, this is it. Apple’s memory guides are thorough and really worth a read.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s