Objective-C style question: do "release" or "nil" properties in dealloc?

Posted by Piotr Czapla on Stack Overflow See other posts from Stack Overflow or by Piotr Czapla
Published on 2011-01-02T18:50:05Z Indexed on 2011/01/02 18:53 UTC
Read the original article Hit count: 156

Filed under:

Hi,

Apple usually release ivars in dealloc but is there anything wrong with nilling the properties in dealloc?

I mean instead of this:

- (void) dealoc(){
   [myRetainedProperty release];
   [super dealloc];
}

write code like this:

- (void) dealoc(){
   self.myRetainedProperty = nil;
   [super dealloc];
} 

I know that it is one additional method call but on the other hand it is safer as it doesn't crashes when you change your property form retain to assign and forget to amend dealloc.

What do you think? Can you think about any other reason to use release instead of setting nil besides performance?

© Stack Overflow or respective owner

Related posts about objective-c