Avoid Retain Cycles In Objective-C
Found an excellent set of rules from Matt Gallagher on how to avoid retain cycles in Objective-C.
Uh-Oh A Class Is Still Retained Somewhere…
A problem that can occur in Objective-C is that when you start sharing objects between classes and increasing the retain count you can end up with a situation where one class inherits from another, and then when you want to release the object does not get released from memory because it is being retained by a class lower down the class hierarchy.
One Basic Rule
Now if this all sounds confusing, Matt explains everything well in his article, and has created a set of 5 rules. Ultimately it comes down to one basic rule:
"an object may only retain something indefinitely if it is hierarchically senior. If you don’t know which object is senior, you must work it out before you retain. If there is no clear senior object — you should redesign so that there is."
For a more detailed detailed explanation (with diagrams) be sure to check out: Rules To Avoid Retain Cycles
[Via: Cocoa With Love]
Would you like to learn iPhone and iPad programming online from professional instructors who have worked for companies such as EA and Disney Mobile?