警告:收到内存警告。等级=1 & 2

发布于 2024-11-01 22:08:58 字数 1771 浏览 4 评论 0原文

我正在制作崩溃的应用程序,并在控制台中发出上述警告。

有两个精灵。

  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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

若能看破又如何 2024-11-08 22:08:58

你在哪里运行[[CCSpriteFrameCache sharedSpriteFrameCache]removeUnusedSpriteFrames];这个语句使用NSObject的performSelectorInBackground方法运行它的后台线程。

Where are you running [[CCSpriteFrameCache sharedSpriteFrameCache] removeUnusedSpriteFrames]; this statement run it background thread using performSelectorInBackground method of NSObject.

攒眉千度 2024-11-08 22:08:58

尝试在动画结束后释放数组。

//可能是这个原因。

[animFrames1 release];
animFrames1 = nil;

Try to release an array after animation ends.

//This may be the reason.

[animFrames1 release];
animFrames1 = nil;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文