In this recipe, we will talk about memory management in iOS using ARC (Automatic Reference Counting). ARC was first introduced in iOS 5 to help developers to manage the app memory. However, while ARC takes care of releasing objects, you still have to set up your reference types correctly to avoid any leaks and retain cycles. In the following recipe, we will try to build a simple app that has a lot of memory issues, and we will see how to catch these issues and what the correct ways to solve them are.
There are some definitions and concepts about memory management that you need to know before starting our demo. In iOS, each object has a reference count in memory, and once this count reaches ZERO, the object will be deallocated from memory. The reference count of any object refers to how many objects have a strong reference to that object. This reference sends a retain message to that object to increase its reference count by ONE. Once any object is done...