具有许多场景的Cocos2D项目不会正确释放内存 [英] Cocos2D project with many scenes does not release memory properly

查看:157
本文介绍了具有许多场景的Cocos2D项目不会正确释放内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个很大的问题,我不太明白为什么会发生。这是这种情况:

I've got a great problem and I don't understand very well why occurs. This is the case:


  • 在Cocos2D中有一个伟大的项目有10个场景。每个场景是一个书的页面与巨大的精灵。它使用Kobold2D 1.0.2实现。

  • 每个页面在单例类中都有通用对象,通过LayerColor放置公共菜单。

  • 精灵是PVR.CCZ RGBA4444中的TexturePacker,iPad内存中的
    每个Spritesheet加载大约为16-20Mb。


  • 在每个页面(类)的init方法中,加载纹理和FrameFile。

  • 在onExit方法每个页面(类),卸载纹理和frameFile。我使用dumpCachedTextureInfo,并说我纹理加载和卸载从内存完美。

  • 当然,我从孩子们删除所有对象。所有我的sprite是在接口部分.h上声明的公共变量,因为我需要在类的每个方法中访问它们。

  • 我的项目是用ARC项目中的Kobold2D集成(但你知道附加的Kobold2D项目有ARC未启用兼容性问题)

  • Have a great project in Cocos2D with 10 scenes. Each scenes is a page of a book with huge sprites. It uses Kobold2D 1.0.2 implementation.
  • Every page has common objects in a singleton class, to put a common menus via LayerColor.
  • The sprites is TexturePacker in PVR.CCZ RGBA4444 and in iPad memory are around 16-20Mb every spritesheet loaded.
  • I use CCTransitionTurnPage for replaceScene for one to the next one.
  • At init method of each page (class), load the texture and FrameFile.
  • At onExit method of each page (class), unload the textures and frameFile. I used the dumpCachedTextureInfo and says me textures load and unload from memory perfectly.
  • Of course, I remove from child all objects. All my sprites are common variables declared on the interface section at .h, because I need to access them in every method of the class.
  • My project is made with Kobold2D integration in a ARC project (but you know the attached Kobold2D project has ARC not enabled for compatibility problem)

事实是当我启动项目时,完美,但记忆正在增加对我做的每一个场景(页)。在7或8个场景之后,仪器,Xcode或iPad本身挂起应用程序而没有任何消息(除了具有最终低内存警告的仪器之外)。Page 2:30Mb。,Page2:40,第3页:54,第4页: 。

The fact is when I start the project, everything seems perfect but memory is increasing for every scenes (page) I made. Page1: 30Mb., Page2: 40, Page 3: 54, Page 4: 65... After 7 or 8 scenes, Instruments, Xcode or the iPad itself hangs the application without any message (except Instruments with a final Low memory Warning).

为什么每个场景后都没有内存释放?也许是因为ARC和没有超级dealloc变量。为什么纹理出现完美,但似乎没有卸载,因为内存正在增长,没有控制,直到崩溃?

Why there's no memory releasing after each scenes? Maybe it's because ARC and the no super dealloc variable. Why textures appears unload perfectly but seems like there's no unload because memory is growing without control until crash?

推荐答案

我有一个类似的问题,内存保留和没有泄漏出现在仪器。我不能得到 - (void)dealloc甚至被调用,直到我写下面的每个场景的.m文件:

I was having a similar problem with memory retention and no leaks showing up in instruments. I couldn't get -(void) dealloc to even get called until I wrote the following into every scene's .m file:

-(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:被调用后,我的内存被释放。希望这对你有一些用处。

After implementing this, my memory was released after every replaceScene: was called. Hope this is of some use to you.

这篇关于具有许多场景的Cocos2D项目不会正确释放内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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