Friday, September 28, 2012

Retain Cycle


Retain Cycle


Retain cycles are a very common source of memory leaks.

We have retain cycles when :
The object A has strong ownership on object B (direct or indirect) and the B has, also strong ownership at A.

That happens for example if the A has an MutableArray of objects B and some from objects B have strong ownership on object A.

the solution on theses cases is to use strong ownership (retain, alloc, etc) to child objects (B) and the child objects to have weak (__weak) ownership at the father.

Apple provides the Instrument profiling tool to help you with that.
When you profile a program, you monitor it while it runs to see what’s happening behind the scenes.



  • Xcode -> 
  • Product -> 
  • Profile … (Instruments launch) choose Leaks 
  • -> Choose Cycles to see if your project has some of them. 




#:from Objective - C programming: The big Nerd Ranch Guide

No comments:

Post a Comment