iOS4 - 快速上下文切换 [英] iOS4 - fast context switching

查看:126
本文介绍了iOS4 - 快速上下文切换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当应用程序进入后台运行状态时,有多少脏内存使用是好的。在Apple视频中,提到脏内存应该尽可能地减少。

When application enters in background running state, how much dirty memory usages is good to go. In apple video it's mentioned that the dirty memory should be reduced as much as we can.

但是在我的应用中,我使用导航控制器来推送和弹出视图。从大约20个不同页面移动后,脏内存使用量达到30 MB左右。

But in my App, I am using navigation controller to push and pop views. After moving from about 20 different pages, the dirty memory usages reaches 30 MB or so.

同样在dismissModalViewControllerAnimated和popViewControllerAnimated上,不会调用dealloc。

Also on "dismissModalViewControllerAnimated" and "popViewControllerAnimated", dealloc is not called.

我有两个疑问:


  1. 上线可以接受多少脏内存?

  2. 什么是导航的替代品控制器支持后退按钮?

提前致谢。

推荐答案

如果没有调用dealloc,你仍然可以保留你的UIViewControllers。

You might still have your UIViewControllers still retained if dealloc isn't being called.

也许你在这些UIViewControllers中设置代理或其他类来保留和引用备份树(循环引用)。

Perhaps are you setting delegates or other classes in these UIViewControllers that retained and referenced back up the tree (circular references).

一种可以调试的方法是在UIViewController中重载retain和release,并设置一个断点并记录retainCount。

A way you can debug this is to overload retain and release in your UIViewController and set a break point and log the retainCount.

这是一个神奇的片段,当我无法弄清楚为什么我还在保留某些东西时,我会跑来跑去帮助我。

Here is a magic snippet I leave running around that helps me a ton when I can't figure out why I'm still retaining something.

- (id)retain
{
    NSLog(@"retain \t%s \tretainCount: %i", __PRETTY_FUNCTION__ , [self retainCount]);
    return [super retain];
}
- (void)release
{
    NSLog(@"release \t%s \tretainCount: %i", __PRETTY_FUNCTION__ , [self retainCount]);
    [super release];
}
- (id)autorelease
{
    NSLog(@"autorelease \t%s \tretainCount: %i", __PRETTY_FUNCTION__ , [self retainCount]);
    return [super autorelease];
}

__ PRETTY_FUNCTION __ 是一个CLang中的特殊隐藏宏,它提供了一个非常好的Objective-C函数名称作为char数组。

__PRETTY_FUNCTION__ is a special hidden macro in CLang that gives a pretty Objective-C function name as a char array.

这篇关于iOS4 - 快速上下文切换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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