IOS应用程序因低内存而被杀死,但未收到内存警告 [英] IOS app killed for Low Memory but no Memory Warning received

查看:428
本文介绍了IOS应用程序因低内存而被杀死,但未收到内存警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在已经遇到问题一段时间了,我想知道是否有人可以提供帮助。
我正在使用主导航控制器和大量UIImage开发IOS应用程序(iPad)。
使用应用程序一段时间后,应用程序因低内存而死(不是在特定视图中),但通过查看iPad日志,我并不总是看到内存不足警告(有时候我会这样做,有时候我不要)。
即使我收到一个,它只是收到的内存不足警告,但我从未得到 1级 2级

I'm stuck with a problem for some time now and I would like to know if anyone can help. I'm developing an IOS app (iPad) using a main navigation controller and a lot of UIImage. After using the application for a while, the app get killed for Low Memory (not in a particular View) but by checking the iPad log, I don't always see a Low Memory Warning (sometimes I do, sometimes I do not). Even when I receive one, it's just "Low Memory Warning received" but I never get "Level 1" or "Level 2".

通过使用xCode中的泄漏仪器,我找不到任何泄漏。

By using the Leak instrument from xCode, I couldn't find any leaks.

可以有人帮忙吗?

推荐答案

内存警告作为通知发送,因此它将在runloop上排队等待发送一旦机会出现。如果你要写一个(故意破坏)循环,如:

A memory warning is sent as a notification, so it'll be queued up on the runloop for dispatch as soon as an opportunity arises. If you were to write a (deliberately broken) loop like:

while(1)
{
    NSString *newString = [NSString string];
}

然后最终你的应用程序因内存不足而被杀,但没有机会它可以接收低内存警告。

Then eventually your app would be killed due to low memory but at no opportunity would it be in a position to receive a low memory warning.

如果由于内存不足而没有收到警告而被杀,那么你可能会造成内存瓶颈对于你自己的某个地方,可能你有某种循环,在自动释放池中留下了很多东西 - 所以,如果你完全通过循环,那么临时对象就会消失,因此没有长期的足迹,但是他们'在你保持循环的过程中重新累积。

If you're being killed due to low memory without receiving a warning then you've probably creating a memory bottleneck for yourself somewhere, likely you have some sort of loop that leaves a lot of things in the autorelease pool — so, if you get all the way through the loop then the temporary objects vanish and hence have no long-term footprint, but they're accumulating all the time you remain in the loop.

为了避免这种情况,你想看看在自己的<$ c $中嵌套循环的内部部分C> NSAutoreleasePool 秒。例如,这个循环:

To avoid that sort of situation you want to look at nesting inner parts of the loop in their own NSAutoreleasePools. For example, this loop:

while(1)
{
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    NSString *newString = [NSString string];
    [pool drain]; // stylistically preferred to release, but equivalent
                  // in reference counted environments
}

将永远持续但不会触发低内存条件。

Will continue forever but won't ever trigger a low memory condition.

这篇关于IOS应用程序因低内存而被杀死,但未收到内存警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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