【问题标题】:Cocos2D/iOS7: continuously increasing memory usage for boilerplate codeCocos2D/iOS7:不断增加样板代码的内存使用量
【发布时间】:2013-10-07 07:44:55
【问题描述】:

当应用程序在没有任何用户交互的情况下运行时,这就是 iOS7 模拟器的样子(我也没有运行我的任何代码,只有样板 Cocos2D):

5.0->6.1 没有这样的问题。产生此问题的代码是 Cocos2D 样板代码,我试图通过注释将其最小化,这是来自 App 委托的最少代码:

    - (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;
}

我还从directorDidReshapeProjectionstartup 中注释掉了CCDirector,以消除我自己的代码。因此,当应用程序现在启动时,我只能在黑屏上看到帧速率。

我从 Instruments 看到的结果相同。

很遗憾无法在设备上测试 iOS 7,但我不希望模拟器会那样做。

更新:

我进行了 2 次标记生成,结果如下。

所有项目都是那些 64 字节的分配。我不知道它们是什么类型的。值得一提的是,我使用的是最新的稳定版 Cocos2D 2.1。

更新 #2:

64字节分配的调用栈。

【问题讨论】:

  • 新的分配有哪些类型?您是否使用过 Instruments 中的“标记生成”按钮?
  • @bneely 用结果更新了我的帖子
  • 您是否在 A 代和 B 代之间执行了任何用户操作,或者应用程序是否自行运行?您是否查看过这些分配的调用堆栈?
  • 不,我没有执行任何用户操作,也没有我的任何代码处理任何东西。我只将样板代码最小化。使用此分配的调用堆栈更新我的帖子。
  • 您的应用使用 ARC 吗?您使用的所有框架都支持 ARC 吗?

标签: ios objective-c memory-leaks cocos2d-iphone ios7


【解决方案1】:

我知道现在回复这个问题为时已晚,但请留在这里。有一个人在谈论 nszoombie,所以如果你用这个选项启用 xcode 的调试,就会导致这个问题。将其关闭并再次检查

【讨论】:

    【解决方案2】:

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

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

    【讨论】:

      【解决方案3】:

      与其说是确认,不如说是答案:这似乎是 iOS 7.0 和 cocos2d 2.1 特有的问题。

      我观察到相同的行为:iOS 7.0 模拟器上的 cocos2d 2.1 会随着时间的推移增加内存使用量。还有很多,每隔几秒增加约 1 MB。但是让我们忽略这一点,模拟器不是真正的设备。

      在设备(装有 iOS 7 的第 5 代 iPod touch)上,内存几乎没有增加。在 5 分钟内使用标记代表示最多增长 15 KB。偶尔会分配一个 10-15 KB 的块,但最终会放手,至少大部分放手。在 5 分钟内添加和保留的内存量约为 5 KB。不多,但对于一个不做任何事情或不响应任何事情的模板应用程序来说,也不仅仅是什么。

      在设备上添加但从未释放的内存大部分都标记为<non-object>,就像在模拟器中一样,中间还有一些 CGPath。因此,这可能表明在 iOS 7 上的 cocos2d 2.1 中可能存在内存管理问题 - 尽管它对大多数应用程序的负面影响太小(每小时“泄漏”约 100 KB)。

      Sprite Kit 和 OpenGL 应用程序以及在 iOS 6 模拟器上运行(我无法在 iOS 6 设备上进行测试)没有显示任何此类问题,实时字节保持稳定,标记代报告根本没有增长。

      【讨论】:

      • 对某些人来说这可能是个大问题……同意,最后我们都必须在设备上进行测试,但是在开发过程中使用模拟器更方便。希望 Cocos2D 小伙伴们能尽快出补丁。
      • 我在 ios7 上观察到与 cocos2d 2.0 相同的情况,与您刚才在 cocos2d 2.1 中描述的设备/模拟器行为相似。
      • 以下主题可能正在描述该错误:cocos2d-iphone.org/forums/topic/… 并且似乎在某些情况下设备也受到影响
      猜你喜欢
      • 2017-09-17
      • 1970-01-01
      • 2011-06-14
      • 1970-01-01
      • 2021-11-08
      • 1970-01-01
      • 1970-01-01
      • 2017-04-02
      • 2018-05-01
      相关资源
      最近更新 更多