iOS4 - 快速上下文切换
当应用程序进入后台运行状态时,有多少脏内存使用量就可以了。在苹果视频中提到应尽可能减少脏内存。
但在我的应用程序中,我使用导航控制器来推送和弹出视图。从大约 20 个不同的页面移动后,脏内存使用量达到 30 MB 左右。
另外,在“dismissModalViewControllerAnimated”和“popViewControllerAnimated”上,不会调用 dealloc。
我有两个疑问:
- 多少脏内存可以上线?
- 支持后退按钮的导航控制器的替代方案是什么?
提前致谢。
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.
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.
Also on "dismissModalViewControllerAnimated" and "popViewControllerAnimated", dealloc is not called.
I have two doubts:
- With how much dirty memory is acceptable to go live?
- What is the alternate of navigation controller to support back button?
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果未调用 dealloc,您可能仍会保留 UIViewController。
也许您在这些 UIViewController 中设置委托或其他类来保留并引用备份树(循环引用)。
调试此问题的一种方法是在 UIViewController 中重载保留和释放,并设置断点并记录保留计数。
这是我留下的一个神奇的片段,当我不明白为什么我仍然保留某些东西时,它对我有很大帮助。
__PRETTY_FUNCTION__
是 CLang 中的一个特殊隐藏宏,它以 char 数组的形式提供漂亮的 Objective-C 函数名称。You might still have your UIViewControllers still retained if dealloc isn't being called.
Perhaps are you setting delegates or other classes in these UIViewControllers that retained and referenced back up the tree (circular references).
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.
__PRETTY_FUNCTION__
is a special hidden macro in CLang that gives a pretty Objective-C function name as a char array.几乎所有视图控制器都具有有效缓存的数据,并且可以在应用程序返回时重新生成前景。想想当应用程序运行时收到内存警告时释放的数据。 (您正在响应内存警告,对吗?)这是您进入后台时应该释放的东西。
UINavigationController
to deal with your back button. I think the problem here is that ifdealloc
is not called on a pop or dismiss, you have a memory leakAlmost all view controllers have data that is effectively cached and can be regenerated when the app returns to the foreground. Think of the data that you release when you get a memory warning when the app is running. (You are responding to memory warnings, right?) It's that stuff that should be released when you go into the background.