我有一个很大的问题,我不太明白为什么会发生。情况是这样的:
每个加载的 spritesheet 大约 16-20Mb。
事实是当我开始这个项目时,一切看起来都很完美,但我制作的每个场景(页面)的内存都在增加。 Page1: 30Mb., Page2: 40, Page 3: 54, Page 4: 65... 在 7 或 8 个场景之后,Instruments、Xcode 或 iPad 本身挂起应用程序而没有任何消息(除了具有最终低内存警告的 Instruments) .
为什么每个场景后没有释放内存?也许是因为 ARC 和没有 super dealloc 变量。为什么纹理看起来完美卸载但似乎没有卸载,因为内存在没有控制的情况下增长直到崩溃?
最佳答案
我在内存保留方面遇到了类似的问题,并且仪器中没有出现泄漏。在我将以下内容写入每个场景的 .m 文件之前,我什至无法调用 -(void) dealloc:
-(void) onExit {
//unschedule selectors to get dealloc to fire off
[self unscheduleAllSelectors];
//remove all textures to free up additional memory. Textures get retained even if the sprite gets released and it doesn't show as a leak. This was my big memory saver
[[CCTextureCache sharedTextureCache] removeAllTextures];
[super onExit];
}
在实现这个之后,我的内存在每次调用 replaceScene: 后被释放。希望这对你有一些用处。
关于memory - 场景多的 Cocos2D 项目没有正确释放内存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9237347/