开发者

Is it safe to call [self <>] inside viewDidUnload?

Is it safe to do something like:

- (void) viewDidUnload {
   [self cleanup] ;
   [super viewDidUnload];
}

Because I hear things such as "self" may not even exist in a non-corrupt form when the v开发者_JS百科iew is unloading, hence it may be unsafe. Is it safe?


It's totally safe. viewDidUnload gets called in low memory situations when the view controller has temporarily deallocated the view to conserve memory. You just don't want to do anything in there that would access your controller's view property, as that would cause the controller to lazy-load the view again. Other than that, calling methods on self in viewDidLoad is totally safe.

You may be thinking of the dealloc method. I've seen people assert that you shouldn't call methods on self in your init or dealloc methods because your object may be in a partially initialized/released state. I guess the fear is that someone will try to modify or override the method you're calling without realizing that it's being called on a partially-formed object. This risk is increased if you don't set your released properties to nil in dealloc.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜