警告:收到内存警告。等级=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 和纹理图集会发生动画变化。但四五次后应用程序崩溃了。在新动画进入 AlphaImage 之前,我还取消了所有帧和纹理。我使用了这个:
[CCSpriteFrameCache purgeSharedSpriteFrameCache];
[CCTextureCache purgeSharedTextureCache];
我正在为应用程序使用高清图像。我浏览了许多文档,他们建议了这些:
[[CCSpriteFrameCache sharedSpriteFrameCache] removeSpriteFrames];
[[CCSpriteFrameCache sharedSpriteFrameCache] removeUnusedSpriteFrames];
但在控制台中,它没有显示任何关于使用这些线删除框架。 我做错了什么吗?
I am making application which is crashing giving the above warning in console.
There are two sprites.
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];
In other method I am initializing AlphaImage using animation.
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];
I have used zwoptex to create plist and Texture atlas.
As train goes and comes back the plist and Texture atlas for animation changes. But after 4 or 5 times application is crashing. I have also deallcated all frames and texture before new animation comes to AlphaImage.i have used this:
[CCSpriteFrameCache purgeSharedSpriteFrameCache];
[CCTextureCache purgeSharedTextureCache];
I am using hd images for the application.I have gone through many documents, they have suggested these:
[[CCSpriteFrameCache sharedSpriteFrameCache] removeSpriteFrames];
[[CCSpriteFrameCache sharedSpriteFrameCache] removeUnusedSpriteFrames];
But in console it is not showing anything about removal of frames using these lines.
Is there something that I am doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你在哪里运行
[[CCSpriteFrameCache sharedSpriteFrameCache]removeUnusedSpriteFrames];
这个语句使用NSObject的performSelectorInBackground方法运行它的后台线程。Where are you running
[[CCSpriteFrameCache sharedSpriteFrameCache] removeUnusedSpriteFrames];
this statement run it background thread using performSelectorInBackground method of NSObject.尝试在动画结束后释放数组。
//可能是这个原因。
Try to release an array after animation ends.
//This may be the reason.