R – Dot notation dealloc


@property (copy) NSString *name;
@property (copy) NSString *orbit;
@property (copy) NSNumber *mass;
@property float surfaceTemp;
@property float rotationSpeed;

Currently Have this

- (void)dealloc{
    [name release];
    name = nil;
    [orbit release];
    orbit = nil;
    [mass release];
    mass = nil;
    [super dealloc];

If I write this using Dot Notation (Objective-C 2.0) Is this right?

- (void)dealloc{
    self.name = nil;
    self.orbit = nil;
    self.mass = nil;
    [super dealloc];


Best Solution

It's bad practice to use your setter methods in -dealloc. Use [name release] instead.

Calling setters during -dealloc may have unintended consequences. If using KVO, setting properties may trigger other code to run causing side effects because your object has already started releasing instance variables. Even when not using KVO this may cause potential problems if your setter method relies on other instance variables that may have already been released.

(updated to reflect comments)

Related Question