Updates below.
When working with (stored) synthesized properties, the best way to fulfill your dealloc responsibilities is to set the nil property. The reason I say this is the βbestβ way is because it ensures that all contracts implied by the declaration of properties are fulfilled. For example, if your property was declared atomic (which will be, unless you specifically declare it non-atomic), the ONLY way to ensure that this property is canceled on dealloc using the same atomic guarantees is to set it to nil using the property in dealloc . It also means that it will behave correctly with respect to any observation of the key values ββof your object. This can be important, especially if you are using Cocoa Bindings.
When performing native memory management for a (possibly private) instance variable without the corresponding property, there are several idioms. The simplest, but the most dangerous, is simply to free the iVar, for example:
- (void)dealloc { [myArray release]; [super dealloc]; }
This will cause the save on iVar to be released, but, as mentioned in other documents, it will exit the potentially obsolete pointer in order to potentially, if mistakenly, access obsolete or not held pointers that may exist, indicating the object is being freed . The next way is the idiom suggested by another answer:
- (void)dealloc { [myArray release], myArray = nil; [super dealloc]; }
An even safer, if more pedantic, idiom for this is:
- (void)dealloc { id temp = myArray; myArray = nil; [temp release]; [super dealloc]; }
This further limits the chances of an obsolete pointer reading by clearing the iVar before releasing the object that it points to. But due to the possibility of reordering instructions, even this is not a 100% guarantee against obsolete reading on all architectures.
While there is still more to say about concurrency and memory management, in the general case, if you have an @synthesized property installer, you should just use it in dealloc. This means that if you change the @property behavior, the dealloc behavior will be automatically correct for the @property declaration.
IMPORTANT NOTE: Using atomic properties! = Thread safety. (Actually, if you ask me that atomic properties are waste, but ...) For more details, see here .
UPDATE
This has recently been confirmed again, and although I support what I said here about atomic safeguards with synthesized conservation properties, and the other content in the original answer is valuable in itself, I feel the need to tell the other side of the story. Dave DeLong referred to some of these comments in the comments, but I decided it was worth adding a detail to the main answer.
I confirm that the only way to maintain atomicity guarantees is to set the nil property through setter. BUT you don't care, and here's why: If the object is dealloc ed, it means (if your graph of the object is correct) that there should not be any live references to this object. If there are no live references to the object, then no one can take care of the guarantees of atomicity of the operation that clears the property.
I also mentioned KVO in the original answer as the reason for using the setter in dealloc , but Dave DeLong mentioned KVO in the comments as counterpoint. He is right, and here's why: Again, if the object is dealloc ed, all KVO observers should already have been removed from it (again, there shouldn't be any live links, KVO or not). In fact, if this is not the case, it will not be long until you see a console message informing you that your object has gone away with the observations that still exist.
In short, while you cannot make atomic warranties equivalent to the synthesizer setter guarantees in dealloc , it never matters (and if that happens, something still doesn't work.)