iPhone内存警告和崩溃-但仪器显示内存不足 [英] iPhone memory warnings and crashes - but Instruments showing lowish memory use

查看:120
本文介绍了iPhone内存警告和崩溃-但仪器显示内存不足的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到一个奇怪的内存问题,正在解决问题,希望您能从其他方面获得一些建议.

I have a strange memory issue I'm having problems resolving and would appreciate some advice as to where else to look.

我拥有的程序(iPhone App)具有一项功能,据此它基本上可以下载文件负载,处理JSON格式的文件,然后将其余文件存储到磁盘. JSON处理占用大量CPU,每个文件可能需要花费几秒钟的时间,因此我有一个NSOperationQueue,其maxConcurrency限制为1,可以处理所有繁重的工作,还有一个队列,用于管理多个文件的下载.

The program I have (iPhone App) has a function whereby it basically downloads loads of files, processes those that are JSON, and stores the rest to disk. The JSON processing is CPU intensive and can take several seconds per file, so I have a NSOperationQueue with maxConcurrency limited to 1 that handles all the heavy lifting, and a queue that manages the multiple files to download.

自从iOS5发布以来,该应用在完成下载序列而不会崩溃的过程中遇到了问题,到目前为止,我一直在尝试;

Ever since iOS5 came out, the App has had problems completing the download sequence without crashing and so far what I have tried is;

1)更改了performSelectorOnBackgroundThread JSON处理,以使用单个NSOperationQueue,以限制处理大型对象的后台线程的数量.

1) Changed the performSelectorOnBackgroundThread JSON processing to use a single NSOperationQueue so as to limit the number of background threads working with large objects.

2)在循环内添加了NSAutoReleasePools,这些循环创建了多个大型的临时对象.

2) Added NSAutoReleasePools inside loops that create multiple, large, transient objects.

3)刷新了sharedURLCache,以确保文件不会在系统缓存中徘徊.

3) Flushed the sharedURLCache to ensure the files aren't hanging around in the system cache.

4)使用NSKeyedArchiver将JSON对象存储到磁盘,并在线程之间而不是实际对象之间传递文件名,以再次尝试减轻当前使用的保留对象的数量和大小.

4) Stored the JSON objects to disk using NSKeyedArchiver and passed the filenames between threads rather than the actual objects, to again try to mitigate the number and size of retained objects currently in use.

所有这些乍一看似乎有所不同,当我查看内存分配时,我现在已经将峰值使用量从刚刚超过20MB(因此难怪崩溃了)降低到了10MB以下,但是该应用仍像以前一样因内存不足而崩溃.

All of these at first seemed to make a difference, and when I look at the memory allocations, I've now got the peak usage down from just over 20MB (hence no wonder it was crashing) to under 10MB, and yet the app is still crashing with low memory as before.

我正在尝试找出导致内存消耗的原因,导致应用程序崩溃,在这种情况下,我遇到了说服Instruments告诉我有用的实际问题.

I'm trying to trace what is eating the memory causing the app to crash and on this occasion I'm having real problems persuading Instruments to tell me anything useful.

这是典型的跟踪记录(在运行iOS 4.3.5的iPhone 3GS上)

Here's a typical trace (on an iPhone 3GS running iOS 4.3.5)

您可以看到PEAK的使用量略超过7MB,但不久之后,您会看到与内存不足有关的两个标志,然后是内存不足紧急情况,随后不久该应用终止.

You can see that the PEAK usage was a tad over 7MB and yet shortly after, you can see the 2 flags pertaining to low memory, and then low memory urgent, followed by the app terminating shortly thereafter.

如果我使用内存监视器,则崩溃的原因似乎很清楚-物理内存已用完-查看下面的浅绿色轨迹.内存不足警告与物理内存用完同时发生(不足为奇).

If I use the memory monitor, the cause of the crash seems clear enough - physical memory is being exhausted - look at the light green trace below. The low memory warnings co-incide (not surprisingly) with the physical memory running out.

也没有显示FWIW的泄漏(我已经在其他运行中做到了).

There are no leaks showing FWIW either (I've done that in other runs).

这不是图像缓存或NSURLConnection缓存,我唯一能想到的就是可能存在一些未被发现的严重泄漏...但是我在识别它们时遇到了问题,因为如果我点击所有分配要查看存在的对象,然后执行命令-A将其全部选中(以便将它们粘贴到电子表格中以查看内存的位置),这时我按了命令-C来复制它们,仪器会滚滚球,永远无法恢复.

It's not image caches or NSURLConnection caches and the only thing I can think of is that perhaps there are some bad leaks that aren't being detected ... but I'm having issues identifying them because if I click into all allocations to see the objects that are live, and then do a command-A to select them all (in order to paste them into a spreadsheet to see where the memory seems to be), at the point I hit command-C to copy them, Instruments beachballs and never recovers.

我真的不知道发生了什么.有人对如何说服仪器给我一些有关使用此存储器的有用信息提供一些建议吗?

I really cant figure out what's going on. Does anyone have some advice on how to persuade instruments to show me some more useful information about what is using this memory?

对不起,我无法发布任何有意义的代码片段...希望仪器屏幕截图至少能使您了解我的来源.

Sorry I can't post any meaningful code fragments ... hopefully the instruments screenshots at least give you an idea about where I'm coming from.

推荐答案

除了发现应用程序中明显的漏洞外,Leaks仪器对于找出任何东西并不是非常有用.

The Leaks instrument isn't terribly useful for figuring out anything but the obvious leaks in your app.

您所描述的是进行堆快照分析的理想人选.

What you are describing is an ideal candidate for heapshot analysis.

tl; dr

tl;dr Heapshot analysis allows you to see exactly how the heap of your application grows between any two points of time (where you determine the points).

这篇关于iPhone内存警告和崩溃-但仪器显示内存不足的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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