本文介绍了新使用XCode Instruments解释iPhone开发的内存警告,需要指导的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在做一个iPhone游戏,接收内存警告,我没有足够的经验来解释。我一直在看一些iTunesU教程,但我仍然不是很好这个..
I am working on an iPhone game which receives memory warning that I am not experienced enough to interpret. I have been watching some iTunesU tutorial but I am still not very good at this..
我在运行我的游戏时收到了各种内存泄漏,我想了解如何
I have received various memory leaks whilst running my game and I wanted to understand how to interpret the stack trace show in Instruments properly.
我附加了ObjectAllocation仪器输出的屏幕截图。即使当我缩放过滤器我不设法过滤ObjectSummary 中的数据。
I attach a screenshot of the ObjectAllocation instrument output . Even when I zoom filter I don't manage to filter the data in the ObjectSummary .
1 发生时,GameScene初始化和所有的数据加载(ParallaxBackground,CCSpriteBatchNode)和精灵和子弹框架(在CCArray的spriteFrames)。
The peaks in memory usage in 1 happen when the GameScene is initialized and all the data is loaded (ParallaxBackground, CCSpriteBatchNode) and Sprites and bullets frames are created (in an CCArray of spriteFrames).
大的蓝色峰值只是在加载时间,但应用程序冻结,然后崩溃只有一段时间,从图中我看到内存使用(蓝色条)下来..所以我不安静得到。此外,当我尝试使用泄漏仪器的应用程序崩溃..
The big blue peak is just at load time but the app freezes and then crashes only after a while and from the graph I see that the memory usage (blue bar) has gone down.. so I don't quiet get that. Also, whenver I try to use the leaks instrument the App crashes..
我知道对于有经验的人来说是一个非常愚蠢的问题,但我只需要一些额外的帮助
I know is a very silly question for someone experienced, but I just need some extra help getting started with this toolset.
我认为内存问题是由于我在sprite缓存类中分配的精灵,但我不确定这一点,因此想要使用Instruments调查此问题,但无法找出如何查看导致内存警告的对象以及如何访问堆栈跟踪。
PS :我运行在一个iPod的第四代,我使用Cocos2D作为库
PS: I am running on an iPod 4th generatio and I am using Cocos2D as library
编辑:我不明白为什么如果Live Bytes只有1.01 MB的应用程序崩溃为什么我仍然收到一个内存警告(见黑旗)。是由于一些指针引用一些空变量或由于过多的内存分配? 1.01 MB对我来说似乎不太多。
I do not also understand why if the Live Bytes are only 1.01 MB the App crashes and why I still receive a memory warning (see black flags). Is it due to some pointer referencing to some null variable or due to an excessive memory allocation? 1.01 MB doesn't seem much to me..
编辑2:按照Marion的建议,我使用活动监视器,意识到有效的实际内存使用是55.39 MB。我误解了活字节字。我将尝试深入挖掘这个问题,并将现在的问题作为不接受,允许其他人贡献。如果我在一两天内没有任何其他答案,我将标记为接受当前的答案。谢谢!
非常感谢。
使用Leaks仪器而不是分配。要找出,目前使用多少内存,使用ActivityMonitor。
If you want to find leaks, use Leaks instrument instead of Allocations. To find out, how much memory use at the moment, use ActivityMonitor.
如果您在cocos2d中遇到内存问题,可以尝试清除缓存。在cocos2d中,您可以清除 CCTextureCache
, CCSpriteFrameCache
, CCAnimationCache
。它将释放未使用的纹理和框架。
If you will have problems with memory in cocos2d, you can try to purge cache. In cocos2d you can purge CCTextureCache
, CCSpriteFrameCache
, CCAnimationCache
. It will release unused textures and frames.
如果你想检查是否所有的unnessesary纹理都从内存中删除,你可以放置断点 CCTextureCache
class并调用,例如 sharedTextureCache
,并看看throw_ dictionary的内容。或者向这个类添加一些方法,以便能够转储缓存的当前状态。
If you want to check if all of unnessesary textures were removed from memory, you can place breakpoint to CCTextureCache
class and call, for example, sharedTextureCache
and look throw the content of textures_ dictionary. Or add some method to this class to be able to dump current state of cache.
这篇关于新使用XCode Instruments解释iPhone开发的内存警告,需要指导的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!