Manual Reference Counting
If you are going to create applications without the use of garbage collection or ARC, or if you have to support code that you can’t migrate to run with ARC, then you need to know how to manage memory. That is, you need to learn about how to work with reference counts.
The general concept is as follows: When an object is created, its initial reference count is set to 1. Each time you need to ensure that the object be kept around, you effectively create a reference to it by incrementing its reference count by 1. This is done by sending the object a retain message, like so:
[myFraction retain];
When you no longer need an object, you decrement its reference count by 1 by sending it a release message, like this:
[myFraction ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access