There is one last concept you need to know to properly manage memory: autorelease. Autorelease is best illustrated and explained using an example.
Imagine you define a method that creates a new object and returns it:
At first glance, the code might look fine, but there is a problem. The voter object is leaked because there is no corresponding release to balance the alloc/init.
To fix this, let’s try adding a release to balance the alloc/init:
The code is fixed, right? Let’s count the references: when voter is initialized, ...