views:

53

answers:

1

First one:

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

Second one:

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

Both methods are delloc, first run the super first, the other run it later, which one is correct or there is no diff between two. thz.

+6  A: 

There is a difference, in that you are guaranteed the existence of ivars in the super class prior to the call to [super dealloc]. After that call, the ivars will be gone.

I don't know if calling [super dealloc] first will create a problem, but the Class Reference for NSObject says you should free your memory first, and then call [super dealloc]

After performing the class-specific deallocation, the subclass method should incorporate superclass versions of dealloc through a message to super

Brandon Bodnár
Calling [super dealloc] first won't always cause a problem, but it won't always work either.
Terry Wilcox