3

我正在为 iPad 开发游戏。当我在 ipad 上运行游戏并为 ipad 骑行场景存在时,由于内存不足会自动关闭应用程序。使用 TexturePacker 将图像转换为 pvr,但从一个场景到另一个场景无法释放内存。

[CCTextureCache sharedTextureCache] removeUnusedTextures];

[[CCSpriteFrameCache sharedSpriteFrameCache] removeUnusedSpriteFrames];

我正在使用这些线路,但还不够。

任何想法?

4

2 回答 2

2

请考虑:

  1. 使用仪器泄漏工具 - 尝试在同一特定时刻(例如,当您准备好运行场景时)制作快照,然后检查它们之间分配的内容。
  2. 尝试在程序的特定部分打印应用程序使用的内存,以找出内存泄漏的位置。
  3. 尝试找出删除场景时未调用哪些 dealloc,然后再深入。
  4. 尝试调用通用函数而不是未使用的函数:

    [[CCSpriteFrameCache sharedSpriteFrameCache] removeSpriteFrames]; [[CCTextureCache sharedTextureCache] removeAllTextures];

于 2012-11-21T11:43:56.627 回答
1

删除未使用的纹理后,使用:

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

CCLOG(@"%@<applicationDidReceiveMemoryWarning> : after purge", self.class);
[[CCTextureCache sharedTextureCache] dumpCachedTextureInfo];

这将列出仍保留在缓存中的纹理,以及它们消耗的内存量。当您希望处理它时仍然存在的任何纹理可能都存在,因为沿线(代码;))的某处,您“以某种方式”保留了它们(例如,将它们添加到数组中)。

于 2012-11-21T11:52:54.470 回答