After synthesizing, do we need release?


on page 71 we are told to create the @property statements with retain for our instance variables, including possessionName. Then we are told to implement them, and REMOVE ALL THE ACCESSOR IMPLEMENTATIONS that we wrote before. However, the setPossessionName setter we wrote before includes [possessionName release], not just the retain and assignment lines. Does the synthesizer setter automatically add this release statement or do we still need to keep this setter method so as to make sure there is no leak? Thanks


The retain in the @property command tells @synthesize how to generate the getters and setters. The [possessionName release] that we wrote in the setter released the prior reference in possessionName.

I suggest rereading pages 67-69 to really understand what’s happening there. Take your time. Understanding what’s happening is hugely important. @property/@synthesize are time savers, but they do not replace the actual understanding.

Lastly, here’s the deal with @synthesize: it generates a getter and/or setter based on the guidance provided by @property. The generated methods follow a specific naming convention. If a method of that name already exists in your code, then @synthesize will assume you want your version used instead and will NOT generate that method.

It’s true (and somewhat unfortunate) that sample @synthesize expansions are provided for @property assign (page 72) and for @property copy (page 73), but not explicitly for @property retain. Just understand that the code we wrote for setting possessionName and serialNumber (bottom of 68 to top of 69) are the setters generated by the corresponding @property/@synthesize statements on page 71.