I know declared property generates accessor method which is someway just syntax sugar.
I found quite a lot people use self.property = nil in their dealloc method.
1) In Apple's Memory Management document, p23 It says:
The only places you shouldn’t use accessor methods to set an instance variable are in init methods and dealloc.
why shouldn't?
2) In apple's Objective-C 2.0, p74
Declared properties fundamentally take the place of accessor method declarations; when you synthesize a property, the compiler only creates any absent accessor methods. There is no direct interaction with the
deallocmethod—properties are not automatically released for you. Declared properties do, however, provide a useful way to cross-check the implementation of yourdeallocmethod: you can look for all the property declarations in your header file and make sure that object properties not markedassignare released, and those markedassignare not released.Note: Typically in a
deallocmethod you shouldreleaseobject instance variables directly (rather than invoking a set accessor and passingnilas the parameter), as illustrated in this example:
- (void)dealloc { [property release]; [super dealloc]; }
If you are using the modern runtime and synthesizing the instance variable, however, you cannot access the instance variable directly, so you must invoke the accessor method:
- (void)dealloc { [self setProperty:nil]; [super dealloc]; }
What does the note mean?
I found [property release]; and [self setProperty:nil]; both work.