使用比较 Xcode iOS9 中的“其他进程"内存不足 [英] Running out of memory in 'Other Processes' in Usage Comparion Xcode iOS9

查看:24
本文介绍了使用比较 Xcode iOS9 中的“其他进程"内存不足的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用在内存为 0.5GB 的设备上崩溃.但是,在 Xcode 中分析内存使用情况 - 它很少超过 140MB.我已经使用仪器来检查泄漏,但没有一个是重要的.

但是,当我运行我的应用程序时,其他进程"使用的内存总是很高.这是启动后的静止状态:

我在代码中的每个循环周期中添加了 1 秒延迟,并发现在每个循环中,其他进程"将每个对象的内存使用量增加了大约 3MB,直到在 0.5GB 设备上,它用完并崩溃.

解决方案

结果证明这是一个相当具体的问题.分配给其他进程的内存实际上是我的应用程序的内存泄漏.它发生在我展平一个有很多孩子的节点时,但没有将包含对所有预展平节点的引用的 NSDictionary 置零.出于某种原因,在分析时没有出现这种内存泄漏.

我还发现了一篇很好的博文:http://battleofbrothers.com/sirryan/memory-usage-in-sprite-kit 关于减少应用的内存占用.如果您正在尝试优化,值得一读.

My app crashes on devices with 0.5GB memory. However, profiling memory usage in Xcode - it rarely goes above 140MB. I've used instruments to check leaks and there are none that are significant.

However, when I run my app, the memory used by 'Other Processes' is always very high. This is the resting state after launching:

I added a 1 second delay in each cycle of a loop in my code, and discovered that on each loop, the 'other processes' increases memory usage by about 3MB per object, until on 0.5GB devices, it runs out and crashes.

This question suggests that these are other apps using that memory, but I have closed every other app and the usage directly correlates with my looping code.

What could be using memory in other processes, that is actually running in my app? And why is my 'Other Processes' using up so much memory?

To give an idea of what I'm doing, I'm pulling data from Parse, then looping through each of the objects returned and creating an SKNode subclass object from the data. I add this node to an array, (for reference) and to the scene. Here's the code I'm doing on the main thread with the delay added. NB the line:

self drawRelationships:[_batches objectAtIndex:_index] forMini:_playerMini];

Is a BFTask and so asynchronous. And I'm dividing the array into smaller batches so I can see incremental memory usage, as each batch is drawn. If I try to draw the whole lot at once, OOM occurs immediately...

- (void)drawNewRelationships
{
    _batches = [NSMutableArray array];
    _index = 0;

    [_playerMini fetchInBackgroundWithBlock:^(PFObject *object, NSError *error) {
        [ParseQuery getNewRelationshipsForMini:_playerMini current:_miniRows.relationshipIds withBlock:^(NSMutableArray *newRelationships) {
            _batches = [self batchArrays:3 fromArray:newRelationships];
            _index = 0;
            [self drawBatches];
        }];
    }];
}

- (void)drawBatches
{
    if ([_batches objectAtIndex:_index]) {
        [self drawRelationships:[_batches objectAtIndex:_index] forMini:_playerMini];
        _index++;
        if (_index < [_batches count]) {
            [self performSelector:@selector(drawBatches) withObject:nil afterDelay:1];
        }
    }
}

The node contains other data, (a couple of arrays, custom object) and I've tried running the app with all that data removed. I've tried running on the main thread and background threads. I've tried using BFTask to do things asynchronously. Everything I've tried ends up with the same behaviour - creating these SKNode objects eats up memory in 'Other Processes', until on low memory devices, it crashes.

It might be worth noting, that this behaviour has only started to occur since iOS9.

Basically, what can be using all this memory in 'other processes' and how can I free it?

Update

I've tried running the Sprite Kit sample app, and even that uses ~550MB in other processes when it launches. Could this be a major Sprite Kit bug?

解决方案

Well it turned out to be a rather specific issue. The memory allocated to other processes was in fact memory leaking from my app. It occurred when I flattened a node with many children, but didn't nil an NSDictionary that contained references to all the pre-flattened nodes. For some reason, this mem leak didn't show up when profiling.

I also found a very good blog post: http://battleofbrothers.com/sirryan/memory-usage-in-sprite-kit on reducing your app's memory footprint. Worth a read if you're trying to optimise.

这篇关于使用比较 Xcode iOS9 中的“其他进程"内存不足的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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