Do I need to call [super viewDidUnload]?

I have seen several Apple examples calling [super viewDidUnload]; and some not. I read an article (a few months ago, so I don’t remember the URL), which said that the call is [super viewDidUnload]; was superfluous, but this did not explain above this.

Is there a specific reason why or why not say super that viewDidUnload ?
And, (if it needs to be done), I call super before setting all my properties to nil , after, or does it matter?

 - (void)viewDidUnload { // Is this necessary? // [super viewDidUnload]; self.tableDataSource = nil; self.titleLabel = nil; // Is it better to call super before or after nil'ing properties? // [super viewDidUnload]; } 

Thanks!

+4
source share
2 answers

1 Is there a specific reason why or why not say super that viewDidUnload?

Honestly, I do not know the consequences of not calling him. You can try not to name it, and everything works smoothly, but imagine that Apple adds some important piece of code that will run when [super viewDidUnload] , what will happen now? There will probably be bad things, and you will spend precious time trying to solve your problem. My rule: when overriding, call super.

2 - I call super before setting all my properties to zero, after or does it matter?

It matters, I watched bad things happen when I called [ super dealloc] before releasing my objects. Similarly, I saw that my user interface was slow because I did my calculations before [super viewDidLoad] . It always depends on what you want to achieve.

The bottom line is what I do in my projects for viewDidUnload :

// free my views

[super viewDidUnload];

As for iOS6:

The method is deprecated .

+7
source

viewDidUnload is similar to dealloc in that you "close" your object - you free up memory and put it in a (semi) inactive state.

The recommended template in Cocoa is to make [super dealloc] at the end of your dealloc subclass, because you need to make sure that all the materials you add to the class can be released before your instance is invalidated by the release. The same idea, although probably not a problem, applies to viewDidUnload .

In general, when creating, let the superclass work first. When destroyed, let it work last.

You do not need to send [super deconstructionMethod] if the implementation of the superclass does nothing. I think this is the case for viewDidUnload , but I'm not sure, and it points in the right direction: the superclass is opaque to you, so if it has not documented that its implementation does nothing, you should always call.

+2
source

All Articles