UIViewController保留计数问题 [英] UIViewController retain count problem

查看:89
本文介绍了UIViewController保留计数问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码创建一个新的UIViewController

I am creating a new UIViewController with the below code

GameViewController *temp = [[GameViewController alloc] initWithNibName:@"GameViewController" bundle:nil];
NSLog(@"retain count%d", [temp retainCount]);
temp.backgroundMusic = backgroundMusic;
self.gameView = temp;
[temp release];     
[self presentModalViewController:gameView animated:YES];                
[gameView release];

但是当我查看保留计数时,我的临时视图控制器返回4.

but when I look at retain counts, my temp view controller returns 4.

这怎么可能?因为它是4,当我关闭视图控制器时,我无法将其从内存中删除,我的游戏正在继续播放。 (我可以看到AI播放的效果)。

How this is possible?? Because it is 4, when I dismiss the view controller I cant remove it from memory and my game is going on playing. (I can see the effects of AI playing).

推荐答案

永远不要使用retainCount,它不会像你认为的那样工作。

Never use retainCount, it does not work the way you think it does.

如果您需要查看对象使用工具的保留,释放和自动释放的位置:

If you need to see where retains, releases and autoreleases occur for an object use instruments:

运行在仪器中,在分配中设置记录参考计数(您必须停止记录以设置选项)。导致选择器运行,停止记录,搜索那里的ivar(datePickerView),向下钻取,你将能够看到所有保留,释放和自动释放发生的位置。

Run in instruments, in Allocations set "Record reference counts" on on (you have to stop recording to set the option). Cause the picker to run, stop recording, search for there ivar (datePickerView), drill down and you will be able to see where all retains, releases and autoreleases occurred.

这篇关于UIViewController保留计数问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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