Question

In an instance of an UIViewController with ARC best practice would be to "release" any retained subviews of the main view (e.g. self.myOutlet = nil) in - viewDidUnload, and my guess is self.view = nil isn't strictly necessary at this point.

What to do if an additional retained property is defined and assigned as...

self.anotherProperty = self.view;

or

_anotherProperty = self.view; // assuming "_anotherProperty" is the ivar

... is self.anotherProperty = nil necessary then?

Was it helpful?

Solution

Nothing in viewDidUnload (I'm assuming we are talking about when running on pre-iOS 6, as views are no longer unloaded in iOS 6, and thus viewDidUnload is no longer called) is "necessary"; it's only an optional opportunity to unload stuff.

But if you wanted to unload stuff properly following the convention for viewDidUnload, should you nil your property? Yes. 1) If not, your property will still retain the view object, preventing it from being deallocated, which is the point of unloading the view. 2) The view has been unloaded, which means self.view is set to nil, and will be set to a newly loaded view when we decide to load the view. If you want your property to always point to self.view, then you need to follow suit and set it to nil on unload and set it to the loaded view in viewDidLoad.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top