设备上的Cocos2d / Box2d应用程序中的内存警告(iPhone / iPad) [英] Memory warnings in Cocos2d/Box2d apps on device (iPhone/iPad)

查看:106
本文介绍了设备上的Cocos2d / Box2d应用程序中的内存警告(iPhone / iPad)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里是Xcode中 profile-> leaks 的信息,我在iPad 2上运行了大约21分钟12秒后崩溃。

Here's the info of profile->leaks in Xcode and I ran it on iPad 2 for about 21 mins 12 seconds before crashing.

live Bytes ---- 5.45 MB

live Bytes ---- 5.45 MB

Living ---- 13547

Living ---- 13547

Transitory ---- 3845036

Transitory ---- 3845036

整体字节 - 720.31 MB

overall Bytes -- 720.31 MB

当应用程式在装置上执行时,

When the app is running on device, the app crashes printing Received Memory Warning in Console.

我不太确定它是如何工作的。

I'm not very sure of how it works.

但请告诉我,如果某个应用在设备上运行了21分钟,则在此运行期间总共使用大约720 MB内存,但活动字节不会超过7.0 MB。

But please tell me if an app runs for 21 minutes on a device, uses an overall of around 720 MB memory in total during this run, yet live bytes never go beyond 7.0 MB.

我接受的应用程序启动时使用3.25 MB作为活字节&它在这个运行期间到活动字节5.45 MB。

但我的问题是: -

But my question is:-

这是一个应用程序,足以在设备上运行时产生崩溃?

Is it an app bad enough to produce crashes while running on device ?

我是否面对一些其他问题?

Am I facing some other problem ?

请指导我。

推荐答案

你可能在CCTextureCache单例中留下了大量的精灵。每当你创建一个CCSprite,纹理缓存(静默),以便下次当你参考它,加载和演示将更快(更快)。在模拟器中运行allocations profiling(参见下面的两张图片):

You probably are leaving tons of sprites in the CCTextureCache singleton. Everytime you create a CCSprite, the texture is cached (silently) so that the next time you refer to it, the loading and presentation will be faster (much faster). Run the allocations profiling in simulator (see two pics below):

顶部的图片来自设备上的分配。最大内存4.4 Mb。

The top image is from allocations profiling on device. Max memory 4.4 Mb.

底部图像是相同的应用程序,SAME游戏序列,而在模拟器中分析(峰值在78 Mb左右)。通过运行在模拟器,我可以看到在分配我的精灵使用的内存。在设备中,此内存不由allocations工具考虑。

The bottom image is the same app, the SAME gameplay sequence, while profiling in the simulator (peaks at around 78 Mb). By running in simulator, i can see in the allocations the memory used by my sprites. In the device, this memory is not accounted for by the allocations tool.

您正在寻找趋势和离散的大跳。如果你永远不回来,你可能会留下未使用的精灵。在我的情况下,我选择从游戏的执行中的特定点的纹理中释放特定的资源。这里是一个来自appController的示例

You are looking for trends and discrete big jumps. If you never come back down, you are probably leaving behind unused sprites. In my case, i choose to free specific resources from the textures at specific point in the game's execution. Here is an example from the appController

- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
    MPLOGERROR(@"Before purge");
    [[CCTextureCache sharedTextureCache] dumpCachedTextureInfo];

    [CCAnimationCache purgeSharedAnimationCache];
    [[CCSpriteFrameCache sharedSpriteFrameCache] removeSpriteFrames];
    [[CCDirector sharedDirector] purgeCachedData];

    MPLOGERROR(@"%After purge");
    [[CCTextureCache sharedTextureCache] dumpCachedTextureInfo];

}  

这是最后一个沟,强力清除。但是你可以在游戏过程中的不同点删除特定的纹理,而不会影响应用程序的感知响应。缓存通常在原则上是合理的,但是在面对有限的资源时可能变得快速棘手。了解它,实验,最终你会找到合适的组合,什么留下/发生什么,为顺利的应用程序的性能。

This is last ditch, brute force cleanout. But you can remove specific textures at different point during game play without impacting the 'perceived' responsiveness of the app. Caches are generally sound in principle, but can become rapidly tricky in the face of constrained resources. Learn about it, experiment, and eventually you will find the right mix of 'what stays/what goes' for smooth application performance.

ps。虽然模拟器适用于某些测试,但不要使用其性能作为基准。模拟器的性能是无意义的,当它涉及到图形,它不使用您的计算机的GPU(这就是为什么你看到图形内存分配:))。

ps. although the simulator is fine for certain tests, dont use its 'performance' as a benchmark. Simulator performance is meaningless when it comes to graphics, it does not use your computer's GPU (and that is why you see the graphic memory allocation :) ).

这篇关于设备上的Cocos2d / Box2d应用程序中的内存警告(iPhone / iPad)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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