Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does it matter when super is called in dealloc?

- (void)dealloc {
    [super dealloc];
    [receivedData release]; receivedData = nil;
}

or

- (void)dealloc {
    [receivedData release]; receivedData = nil;
    [super dealloc];
}
like image 564
Sheehan Alam Avatar asked Aug 19 '10 15:08

Sheehan Alam


2 Answers

Yes, it absolutely maters when [super dealloc] is called. Once [super dealloc] is called, you can no longer rely on the NSObject (or whatever your root class is) machinery to function properly. Afterall, your super-class' -dealloc method should call its superclass' etc. until the root class' -dealloc method is called. At that point, everything that these classes allocate to do their job is potentially gone and you're in undefined territory if you try to use any of it.

Your -dealloc method should always look like

- (void)dealloc
{
   // release my own stuff first

   [super dealloc];
}
like image 148
Barry Wark Avatar answered Sep 22 '22 02:09

Barry Wark


Yes. Last. Always.

like image 45
Steven Noyes Avatar answered Sep 19 '22 02:09

Steven Noyes