【问题标题】:Presentmodalviewcontroller method problem with retain countPresentmodalviewcontroller 方法的保留计数问题
【发布时间】:2010-04-14 09:58:22
【问题描述】:

我正在尝试展示一个模态视图控制器。我已阅读文档,但有些奇怪。这是我的代码:

NSLog(@"rc: %d", [modalViewController retainCount]);
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:modalViewController];
[self presentModalViewController:navigationController animated:YES];
[navigationController release];
NSLog(@"rc: %d", [modalViewController retainCount]);

然后在控制台上出现:

rc: 2
rc: 24

而且我觉得 24 很奇怪……你瘦什么?为什么会这样?

【问题讨论】:

  • 我不知道你的具体问题,但是 -[NSObject retainCount] 返回一个 NSUInteger,所以你应该在格式字符串中使用 %u,而不是 %d。
  • 好的,我已经改成%u了。都是一样的。

标签: iphone objective-c ipad


【解决方案1】:

您不必过多担心保留计数的值。当使用这样的系统调用时,可能会发生任意数量的保留/释放周期。

如果您的视图控制器以模态方式正确显示,那么问题出在哪里?

【讨论】:

  • 关闭 ModalViewController 后出现内存泄漏,但找不到泄漏的位置。 :(
  • 好的,我找到了。我设置了这样的属性: self.prop = [data retain];我现在很为自己生气……
  • 我不同意“不要担心保留计数太多”......正如 Infinity 所说,他们发现 [data retain] 调用存在问题,这会导致稍后发出。 “不担心保留计数”是永远不对的。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-03-15
  • 2011-11-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多