警告:收到内存警告。 Level = 1&2
问题描述:
我正在崩溃的应用程序在控制台中发出上述警告。警告:收到内存警告。 Level = 1&2
有两个精灵。
Train=[CCSprite spriteWithFile:@"train.png"];
[self addChild:train z:0 tag:1];
AlphaImage=[CCSprite node];
AlphaImage.position=ccp(245,155);
[Train addChild:AlphaImage z:1 tag:2];
在其他方法我使用动画初始化AlphaImage。
CCSpriteFrameCache *frameCache1 =[CCSpriteFrameCache sharedSpriteFrameCache];
[frameCache1 addSpriteFramesWithFile:plist1];
CCSpriteBatchNode *danceSheet1 = [CCSpriteBatchNode batchNodeWithFile:png1];
[self addChild:danceSheet1];
NSMutableArray *animFrames1 = [NSMutableArray arrayWithCapacity:frame[x]];
for(int i = 1; i < frame[x]+1; i++) {
NSString *namef1=[NSString stringWithFormat:@"%@%i.png",alpha1,i];
CCSpriteFrame *frame1 = [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:namef1];
[animFrames1 addObject:frame1];
}
CCAnimation *anim1 = [CCAnimation animationWithFrames:animFrames1 delay:0.3f];
CCAnimate *animN1 = [CCAnimate actionWithAnimation:anim1];
CCRepeatForever *repeat1 = [CCRepeatForever actionWithAction:animN1];
[AlphaImage runAction:repeat1];
我已经使用zwoptex创建plist和纹理图集。
随着火车驶过并返回动画更改的plist和Texture Atlas。但是在4或5次应用程序崩溃之后。我也deallcated所有帧和纹理之前新的动画来AlphaImage.i都用这个:
[CCSpriteFrameCache purgeSharedSpriteFrameCache];
[CCTextureCache purgeSharedTextureCache];
我使用的application.I经历了许多文件了高清图像,他们建议这些:
[[CCSpriteFrameCache sharedSpriteFrameCache] removeSpriteFrames];
[[CCSpriteFrameCache sharedSpriteFrameCache] removeUnusedSpriteFrames];
但在控制台中,它没有显示任何有关使用这些行删除帧的信息。 有什么我做错了吗?
答
你在哪里运行[[CCSpriteFrameCache sharedSpriteFrameCache] removeUnusedSpriteFrames];
这条语句使用NSObject的performSelectorInBackground方法运行它后台线程。
答
尝试在动画结束后释放数组。
//这可能是原因。
[animFrames1 release];
animFrames1 = nil;
在我的AllReset方法中,我有动画代码(上面的代码),在此之前我调用了包含此代码的removeUnused方法。 – user392406 2011-04-14 08:01:11
将此页面引用为performSelectorInBackground - http://blog.datispars.com/tasks-in-background-thread-cocoa-performselectorinbackground/ – nishantcm 2011-04-14 08:31:45
performSelectorInBackground对选择器不响应它将进入循环。 – user392406 2011-04-15 06:26:10