Don’t Use Accessor Methods in Initializer Methods and dealloc

Here's an example I wrote which demonstrates two things:

  • how initialization can be reordered
  • how leaks can be introduced

Initializing a property, dot notation

Although the example focuses on initialization, dealloc is susceptible to similar categories of problems. As one specific example: an object may partially resurrect itself in dealloc, and reference count imbalances become a potential danger.

Briefly, you want to focus on correct initialization and cleanup of the data your objects need -- rather than the behavioral concerns/influence of your objects through any subclasses.


More reading:

Why myInstance = nil instead of self.myInstance = nil?

Should I refer to self.property in the init method with ARC?

Best way to set a retained property to a newly created object