Cocos2D/iOS7:不断增加样板代码的内存使用
当应用程序只是在没有任何用户交互的情况下运行时(我也没有运行我的任何代码,只有样板Cocos2D),iOS7模拟器就是这样: 5.0->6.1中没有此类问题。产生此问题的代码是Cocos2D样板代码,我试图通过注释将其最小化,这是来自App delegate的最小代码:Cocos2D/iOS7:不断增加样板代码的内存使用,ios,objective-c,memory-leaks,cocos2d-iphone,ios7,Ios,Objective C,Memory Leaks,Cocos2d Iphone,Ios7,当应用程序只是在没有任何用户交互的情况下运行时(我也没有运行我的任何代码,只有样板Cocos2D),iOS7模拟器就是这样: 5.0->6.1中没有此类问题。产生此问题的代码是Cocos2D样板代码,我试图通过注释将其最小化,这是来自App delegate的最小代码: - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
- (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;
}
我还从directorddreshapeproject
启动中注释掉了CCDirector
,以消除我自己的代码。所以当应用程序现在启动时,我只能在黑屏上看到帧速率
我从仪器上看到了同样的结果
不幸的是,我无法在设备上测试iOS7,但我不希望模拟器会这样做
更新:
我做了两代标记,结果如下
所有项目都是那些64字节的分配。我不知道他们是什么类型的。值得一提的是,我正在使用最新的稳定cocos2d2.1
更新#2:
64字节分配的调用堆栈
与其说是答案,不如说是确认:这似乎是iOS 7.0和cocos2d 2.1特有的问题 我观察到了同样的行为:iOS7.0模拟器上的CoCoS2D2.1随着时间的推移会增加内存使用。而且每几秒钟就有大约1MB的内存。但是让我们忽略这一点,模拟器不是一个真正的设备 在一台设备(iPodtouch第五代iOS7)上,内存几乎没有增加。在5分钟内使用标记的世代表示最多增长15 KB。偶尔会分配一个10-15KB的块,但最终会放弃,至少是大部分。在5分钟内添加和保留的内存量约为5 KB。对于一个不做任何事情或不响应任何事情的模板应用程序来说,没有太多,但也比没有更多 在模拟器中,在设备上添加但从未释放的内存大多标记为
,中间有一些CGPath。因此,这可能表明iOS 7上的CoCoS2D2.1可能存在内存管理问题——尽管它对大多数应用程序的负面影响太小(每小时约100 KB“泄漏”)
Sprite Kit和OpenGL应用程序以及在iOS 6模拟器上运行的应用程序(我无法在iOS 6设备上测试)没有显示任何此类问题,活动字节保持稳定,标记的代报告没有任何增长。您确定没有启用僵尸对象吗
单击产品->编辑方案,在诊断选项卡上,如果选中了“启用僵尸对象”,请取消选中它,然后重试 我知道现在回答这个问题已经太晚了,但还是留在这里吧。有人在谈论nszoombie,所以如果您使用此选项启用xcode调试,将导致此问题。将其关闭并再次检查新分配的类型是什么?您是否使用过Instruments中的“Mark Generation”(标记生成)按钮?@B每次都会用结果更新我的帖子您是否在A代和B代之间执行过任何用户操作,或者应用程序是否自行运行?你看过这些分配的调用堆栈了吗?没有,我没有执行任何用户操作,也没有处理任何操作的代码。我已经最小化到样板代码而已。正在使用此分配的调用堆栈更新我的帖子。你的应用程序是否使用ARC?您使用的所有框架都支持ARC吗?对于一些人来说,这可能是一个重要的问题。。。同意,最后我们都必须在设备上测试,但在开发过程中使用模拟器更方便。希望Cocos2D的家伙们能尽快发布补丁。我观察到ios7上的Cocos2D 2.0也有同样的情况,类似于您刚才在这里描述的Cocos2D 2.1的设备/模拟器行为。下面的主题可能会描述这个bug:在某些情况下,设备似乎也会受到影响