iOS:我为什么要首先在viewDidUnload中释放dealloc然后释放dealloc方法? [英] iOS: why should I deallocate first in viewDidUnload and then dealloc methods?

查看:253
本文介绍了iOS:我为什么要首先在viewDidUnload中释放dealloc然后释放dealloc方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Apple文档页面上找到了一个示例,它按如下方式释放内存:

I've found on Apple documentation pages an example in which they deallocate the memory as follows:

- (void)viewDidUnload
{
  self.mapAnnotations = nil;
  [super viewDidUnload];

  // Relinquish ownership of anything that can be recreated in viewDidLoad or on demand.
  // For example: self.myOutlet = nil;
}

- (void)dealloc
{
  [mapAnnotations release];
  [super dealloc];
}

我想知道为什么


  1. 他们首先在viewDidUnload中将mapAnnotation设置为nil,然后以dealloc方法释放,

  1. they first set mapAnnotation to nil in viewDidUnload and then they release in dealloc method and

为什么他们引用使用mapAnnotation有和没有自己。

why they refer using to mapAnnotation with and without self.

这是可下载的例子: MapCallouts示例

推荐答案

你应该问的问题是:什么时候 viewDidUnload 调用?

The question you should be asking is: when is viewDidUnload called?

简而言之,它是在低内存情况下调用的,你不想释放整个控制器,即当你想要<$ c时要调用$ c> dealloc 。

In short it's called in low memory situations where you don't want to deallocate the whole controller, i.e., when you don't want dealloc to be called.

您可以将 viewDidUnload 视为与 viewDidLoad 相反的 loadView deall oc init 相反。 (实际上它可能比当然要复杂一点。)

You can think of viewDidUnload as the opposite of viewDidLoad of loadView whereas dealloc is the opposite of init. (In practice it can get a bit more complicated than that of course.)

这篇关于iOS:我为什么要首先在viewDidUnload中释放dealloc然后释放dealloc方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆