iOS内存使用量不断增长 [英] iOS Constantly growing memory usage

查看:580
本文介绍了iOS内存使用量不断增长的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在开发我前一段时间开始的游戏.进度很好,一切运行顺利,但是我决定尝试使用XCode Instruments检查我的代码中是否存在泄漏.我正在使用ARC,并且只有在删除其他对象时才添加新对象(游戏内部工作的一部分),但是总内存大小在运行时会不断增长.

I'm currently working on a game I started a while ago. Progress was good and everything runs smoothly, but I decided to try using XCode Instruments to check for any leaks in my code. I am using ARC and new objects are only added when others are deleted (part of my game's inner-workings), but the total memory size keeps growing as it runs.

我的游戏是完全按照程序生成的,不需要任何资源,它还只使用了仅用颜色映射的几个多边形,因此没有纹理.我希望它只需要几个MB即可运行(开始时是这样),但是它还在不断增长.

My game is completely procedurally generated and requires no assets, it also only uses a couple polygons mapped only with colors, so there are no textures. I expect it should only need a couple MBs to run (which it starts out with) but it just keeps growing.

现在,我注意到一些有趣的事情了……用尽了大部分数据的是一个名为IOAccelResource的条目.这很奇怪,因为我不使用任何加速度计/陀螺仪/罗盘数据.我什至没有在我的项目中引用CoreMotion框架.

Now, I noticed something interesting... What uses up the majority of the data is an entry called IOAccelResource. Which is odd because I don't use any accelerometer/gyroscope/compass data. I don't even have the CoreMotion framework referenced in my project.

数据的第二个主要用途是四个不断增长的malloc的集合.还有更多保持相对不变的方式.

The second major use of data is a collection of four mallocs that keep growing. There are a couple more that stay relatively the same.

尽管这两个条目未被程序视为泄漏.而且,当我告诉XCode分析我的代码时,它没有指出任何问题.

These two entries aren't considered leaks by the program though. And when I tell XCode to analyze my code it doesn't point to any problems.

所有其他条目都很小,并且围绕同一点波动,或者保持不变.

All of the other entries are pretty small and fluctuate around the same point, or just stay the same.

这是麻烦条目的屏幕截图:

Here is a screenshot of the troublesome entries:

有什么建议吗?

推荐答案

如果您指的是总字节数"或"#Overall(元素数)"不断增长的情况,那么这通常不会出现问题,因为这会跟踪总数内存使用情况(换句话说,它不考虑释放的内存).

If you are referring to the "Overall Bytes" or "#Overall (elements)" keep on growing, that is not usually a problem as this tracks the total memory usage (in other words, it does not account for released memory).

您应该查看的是实时字节数"和#生活(元素)",并确保它们符合您的期望.

What you should be looking at is the "Live Bytes" and "#Living (elements)" and ensuring that it is in line with your expectations.

您还将看到,如果总字节数"持续增长,那不会使您的应用程序崩溃.另一方面,如果实时字节数"持续增长,则会使您的应用崩溃.

You will also see that if the "Overall Bytes" keeps growing, that will not crash your app. On the other hand, if the "Live Bytes" keep growing, that will crash your app.

Apple已经意识到仪器配置文件中的信息太多,这就是为什么在xCode5中,它将重要信息直接提取到xCode中的原因:运行应用程序时,单击导航器中的第6个图标(调试导航器) (xCode的左列).您将看到内存"指示器,该指示器仅跟踪活动字节".

Apple has realized that there is too much information in the instruments profile and that is why in xCode5, it has distilled the important information into xCode directly: When running your app, click on the 6th icon (debug Navigator) in the Navigator (left column of xCode). You will see the Memory indicator which will track "Live Bytes" only.

此外,如果您有权访问WWDC 2013视频,请查看会话410:解决内存问题.

Also if you have access to WWDC 2013 videos, check out session 410: Fixing memory issues.

希望这会有所帮助.

这篇关于iOS内存使用量不断增长的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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