Both existing answers are incorrect.
@synthesize creates setters and getters that look like this:
- (void)setMyArray:(NSArray*)array { if( myArray != array ) { [myArray release]; myArray = [array retain]; } } - (NSArray*)myArray { return myArray; }
(Note that they are not exactly the same, and differ if you specify a copy or other attributes, but this is the basic formula). Now we can see that self.myArray = nil; will release the old array. self.myArray and myArray are not interchangeable for customization purposes. Moreover, self.myArray = nil; will continue to work in the world of garbage collection.
As Dave Delong points out, self.myArray = nil will notify any observer myArray of the changed value, which can be a problem if you do this in your dealloc method. To avoid this case, your dealloc will look something like this:
- (void)dealloc { [myArray release]; myArray = nil; [super dealloc]; }
(note myArray = nil; is a stylistic choice here.)
source share