0
votes

In an implementation of dealloc, you should not invoke the superclass’s implementation. You override this method to dispose of resources other than the object’s instance variables, for example:

  • (void)dealloc { free(myBigBlockOfMemory); }

Above says we should not invoke the superclass's implementation. But below it says we should "incorporate superclass versions of dealloc through a message to super." So there seems to be some conflict between the two paragraphs. It must be due to something that I've missed. Hope somebody can explain this ...

If you are using manual reference counting, subclasses must implement their own versions of dealloc to allow the release of any additional memory consumed by the object—such as dynamically allocated storage for data or object instance variables owned by the deallocated object. After performing the class-specific deallocation, the subclass method should incorporate superclass versions of dealloc through a message to super:

  • (void)dealloc { [companion release]; free(myBigBlockOfMemory); [super dealloc]; }

http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/nsobject_Class/Reference/Reference.html

1

1 Answers

6
votes

Your first quote is for when automatic reference counting (ARC) is enabled, and your second quote is for when ARC is not enabled. ARC is a new feature provided in SDK 5.0 that eliminates much of the manual memory management that needed to be done by the programmer.

See Transitioning to ARC Release Notes, in particular these statements:

You may implement a dealloc method if you need to manage resources other than releasing instance variables. You do not have to (indeed you cannot) release instance variables...

Custom dealloc methods in ARC do not require a call to [super dealloc] (it actually results in a compiler error). The chaining to super is automated and enforced by the compiler.