Interface Builder sets control outlets to nil -- why?

ios, objective-c, xcode

Solution

`viewDidUnload` may be called and may be not called. It depends on the current memory usage. `dealloc` is a place where you should clean all your properties (like arrays, custom objects). In `viewDidUnload` you clean views and perhaps objects created to support the view. `viewDidUnload` mean that your view is unloaded (but not whole view controller) and it may be created and loaded again (in viewDidLoad, of course) in the future.

- Why to nil - Objective-C Difference between setting nil and releasing

- Understanding How Views Are Loaded and Unloaded

Problem

Using xcode 4.2 for iPhone app, without ARC --- When I create an outlet using the interface builder xcode adds two lines of code to my viewController. One in viewDidUnload: -- `[self setMyOutlet:nil]` and second in dealloc -- `[myOutlet release]`. I understand the latter (the release). But why set the outlet to nil in viewDidUnload. Doesn't viewDidUnload get called before dealloc and won't setting the outlet to nil negate the release operation in dealloc? Setting to nil makes sense I would think for building a Mac application which is using garbage collection -- but it doesn't make sense for an iPhone app. Why does the interface builder do this? Should I delete the lines which set the outlets to nil?

Original source

Related problems