Objective-C: Memory Management
For every object that an application uses, memory must be allocated and subsequently deallocated to ensure that memory is being used efficiently. This is what we refer to as memory management. One of the primary goals of any memory management system is to reduce the amount of memory used at any given time. To better understand how to manage memory efficiently in Objective-C, we should probably cover the basics of our two sources of memory: the stack and the heap . The stack is a section of memory that holds local variables, in addition to internal temporary values. When you call a method, the frame — the variables and operations that the function contains — moves briefly to the top of the stack. For the duration of that function call, the variables used are stored in the stack. After execution is complete, the frame moves off the top of the stack and the memory is deallocated. Programmers don’t take any explicit action over the stack — other than when...