0

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?

4

1 回答 1

0

viewDidUnload(我假设我们正在谈论在 iOS 6 之前的版本上运行时,因为在 iOS 6 中不再卸载视图,因此不再viewDidUnload调用)是“必要的”;这只是卸载东西的可选机会。

但是如果你想按照 的约定正确卸载东西viewDidUnload,你应该 nil 你的财产吗?是的。1)如果没有,你的属性仍然会保留视图对象,防止它被释放,这是卸载视图的点。2) 视图已经被卸载,也self.view就是设置为nil,当我们决定加载视图时,会被设置为新加载的视图。如果您希望您的属性始终指向self.view,那么您需要效仿并在卸载时将其设置为 nil 并将其设置为viewDidLoad.

于 2012-11-05T21:44:40.257 回答