Cocos2D/iOS7:样板代码内存使用不断增加

8
这是iOS7模拟器中应用程序在没有任何用户交互的情况下运行时的样子(同时我没有运行任何我的代码,只有Cocos2D的样板代码): enter image description here 5.0->6.1版本没有这种问题。产生此问题的代码为Cocos2D样板代码,我试图通过注释来最小化它,并且这是App delegate中的最小代码。
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Create the main window
    window_ = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];


    // CCGLView creation
    CCGLView *glView = [CCGLView viewWithFrame:[window_ bounds]
                                   pixelFormat:kEAGLColorFormatRGB565
                                   depthFormat:0
                            preserveBackbuffer:NO
                                    sharegroup:nil
                                 multiSampling:NO
                               numberOfSamples:0];

    director_ = (CCDirectorIOS*) [CCDirector sharedDirector];

    director_.wantsFullScreenLayout = YES;

    // Display FSP and SPF
    [director_ setDisplayStats:YES];

    // set FPS at 60
    [director_ setAnimationInterval:1.0/60];

    // attach the openglView to the director
    [director_ setView:glView];

    [glView setMultipleTouchEnabled:YES];

    // 2D projection
    [director_ setProjection:kCCDirectorProjection2D];
    //  [director setProjection:kCCDirectorProjection3D];

    // Enables High Res mode (Retina Display) on iPhone 4 and maintains low res on all other devices
    if( ! [director_ enableRetinaDisplay:YES] )
        CCLOG(@"Retina Display Not supported");

    // Default texture format for PNG/BMP/TIFF/JPEG/GIF images
    // It can be RGBA8888, RGBA4444, RGB5_A1, RGB565
    // You can change this setting at any time.
    [CCTexture2D setDefaultAlphaPixelFormat:kCCTexture2DPixelFormat_RGBA8888];

    // If the 1st suffix is not found and if fallback is enabled then fallback suffixes are going to searched. If none is found, it will try with the name without suffix.
    // On iPad HD  : "-ipadhd", "-ipad",  "-hd"
    // On iPad     : "-ipad", "-hd"
    // On iPhone HD: "-hd"
    CCFileUtils *sharedFileUtils = [CCFileUtils sharedFileUtils];
    [sharedFileUtils setEnableFallbackSuffixes:NO];             // Default: NO. No fallback suffixes are going to be used
    [sharedFileUtils setiPhoneRetinaDisplaySuffix:@"-hd"];      // Default on iPhone RetinaDisplay is "-hd"
    [sharedFileUtils setiPadSuffix:@"-ipad"];                   // Default on iPad is "ipad"
    [sharedFileUtils setiPadRetinaDisplaySuffix:@"-ipadhd"];    // Default on iPad RetinaDisplay is "-ipadhd"

    // Assume that PVR images have premultiplied alpha
    [CCTexture2D PVRImagesHavePremultipliedAlpha:YES];

    // Create a Navigation Controller with the Director
    navController_ = [[MyNavigationController alloc] initWithRootViewController:director_];
    navController_.navigationBarHidden = YES;

    // for rotation and other messages
    [director_ setDelegate:navController_];

    // set the Navigation Controller as the root view controller
    [window_ setRootViewController:navController_];

    // make main window visible
    [window_ makeKeyAndVisible];

    return YES;
}

我在directorDidReshapeProjection启动时注释掉了CCDirector,以消除我的代码。所以现在应用程序启动时,我只看到黑屏上的帧速率。
从Instruments看到的结果也是一样的。
不幸的是,无法在设备上测试iOS 7,但我不认为模拟器会像那样表现。
更新:
我进行了2个标记生成,以下是结果。 enter image description here 所有项目都是那些64字节的分配。我不知道它们是什么类型。值得一提的是,我使用的是最新稳定的Cocos2D 2.1。
更新#2:
64字节分配的调用堆栈。 enter image description here

新分配的类型是什么?您是否在Instruments中使用了“标记生成”按钮? - bneely
@bneely更新了我的帖子并附上了结果。 - Pablo
你的应用程序使用ARC吗?你使用的所有框架都支持ARC吗? - bneely
是的,我的应用正在使用ARC。不过,Cocos2D正在使用手动内存管理,并且我已经将其源文件设置为-fno-objc-arc。请注意,这只会在iOS7上发生。 - Pablo
也许你应该向cocos2d报告这个bug,不过最好先在设备上确认一下。我马上试一下。 - CodeSmile
显示剩余7条评论
3个回答

3
这不是一个答案,而是一个确认:这似乎是iOS 7.0和cocos2d 2.1特定的问题。
我也观察到了相同的行为:在iOS 7.0模拟器上,cocos2d 2.1的内存使用量随着时间的推移而增加。而且每隔几秒钟就会增加很多,大约每秒增加1 MB左右,但让我们不去理会它,因为模拟器不是真正的设备。
在设备上(iPod touch 第五代,带有 iOS 7),内存几乎不会增加。在 5 分钟内使用标记的世代,最多只会增长约 15 KB。偶尔会分配一个 10-15 KB 的块,但最终会释放掉,至少大部分会释放掉。在 5 分钟内增加并保留的内存约为 5 KB。对于一个什么都不做或响应的模板应用程序来说,不算太多,但也不是零。
设备上添加但永远不会被释放的内存大多标记为,就像模拟器中一样,中间会插入一些CGPath。因此,这可能表明cocos2d 2.1在iOS 7上存在内存管理问题,尽管它对大多数应用程序没有负面影响(每小时泄漏约100 KB)。
Sprite Kit和OpenGL应用程序以及在iOS 6模拟器上运行(我无法在iOS 6设备上测试)都没有显示出任何此类问题,活动字节保持稳定,标记的世代报告完全没有增长。

对于一些人来说,这可能是一个重要的问题...虽然我们最终都必须在设备上进行测试,但在开发过程中使用模拟器更加方便。希望Cocos2D团队能尽快发布补丁。 - Pablo
我在iOS7上使用cocos2d 2.0也观察到了相同的情况,与你在这里描述cocos2d 2.1的类似设备/模拟器行为。 - YvesLeBorg
以下主题可能描述了错误:http://www.cocos2d-iphone.org/forums/topic/cocos2d-2-0-bug-render-time-peaks-endless-memory-allocation-2/page/2/,在某些情况下设备也会受到影响。 - Pablo

0

我知道回复这个问题已经太晚了,但是还是留在这里吧。有一个人谈论nszoombie,所以如果你使用xcode的调试选项启用了它,就会导致这个问题。关闭它然后再检查一下。


0

你确定没有启用僵尸对象吗?

点击你的产品 -> 编辑方案,在诊断选项卡中,如果你勾选了“启用僵尸对象”,请取消勾选并重试。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接