Cocos2d iphone 氯化铵和氯化铵泄漏?

Cocos2d iphone 氯化铵和氯化铵泄漏?,cocos2d-iphone,Cocos2d Iphone,在我的@Monster类中,有3种不同的行走动画 “怪物,h” “怪物,m” +(id)monsterInit。。。 { 怪物*精灵=…//初始化 NSMutableArray*frameArray=[NSMutableArray]; 对于(int i=0;i

在我的@Monster类中,有3种不同的行走动画

“怪物,h”

“怪物,m”

+(id)monsterInit。。。
{
怪物*精灵=…//初始化
NSMutableArray*frameArray=[NSMutableArray];
对于(int i=0;i<3;i++){
NSString*文件名=[NSString stringWithFormation:@“%d.png”,i];
[frameArray addObject[[CCSpriteFrameCache sharedSpriteFrameCache]spriteFrameByName:fileName]];
}
cAnimation*walk=[cAnimation animationWithFrames:frameArray延迟:0.1f];
self.fWalk=[CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation:walk restoreOriginalFrame:NO]];
[frameArray removeAllObjects];
对于(int i=3;i<6;i++){
NSString*文件名=[NSString stringWithFormation:@“%d.png”,i];
[frameArray addObject[[CCSpriteFrameCache sharedSpriteFrameCache]spriteFrameByName:fileName]];
}
walk=[cAnimation animationWithFrames:frameArray延迟:0.1f];
sprite.bWalk=[CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation:walk restoreOriginalFrame:NO]];
[frameArray removeAllObjects];
对于(int i=6;i<9;i++){
NSString*文件名=[NSString stringWithFormation:@“%d.png”,i];
[frameArray addObject[[CCSpriteFrameCache sharedSpriteFrameCache]spriteFrameByName:fileName]];
}
walk=[cAnimation animationWithFrames:frameArray延迟:0.1f];
sprite.hWalk=[CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation:walk restoreOriginalFrame:NO]];
返回精灵;
}
-(无效)解除锁定
{
[fWalk释放];
[bWalk释放];
[hWalk释放];
[super dealoc];
}
当我使用性能工具运行此应用程序时-泄漏。仪器显示的语句是“cAnimation*walk…”、“self.fWalk…”、“walk=…”、“self.bWalk…”、“walk=…”、“self.hWalk…”导致内存泄漏

我检查了关于CCAnimation和CCAnimate的源代码,它们都是“自动释放”。我不知道为什么会发生这种泄漏。
知道怎么做吗?

如果以后打算使用这些操作,则必须保留这些操作,因为使用actionWithAction方法创建时,这些操作会自动删除。像这样:

self.fWalk = [[CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation:walk restoreOriginalFrame:NO]] retain];

否则,怪物类不会拥有这些动作,当您离开init方法时,这些动作会自动删除。

好,但当您将所有动画保存到如下数组中时:

CCAnimation *anim = [CCAnimation animationWithSpriteFrames:animFrames delay:pDelay];
CCAnimate *animate = [CCAnimate actionWithAnimation:anim];
CCCallFunc *callback = [CCCallFunc actionWithTarget:pTarget selector:pCallBack];
CCSequence *seq = [CCSequence actions:animate, callback , nil];

NSMutableDictionary *animations;

[animations setValue:seq forKey:pName];

- (void)dealloc {
    for (NSString* key in [animations allKeys]) {
        CCAction *action = [animations objectForKey:key];
        [self stopAction:action];
        [action stop];
    }

    [animations removeAllObjects];
    //[[CCSpriteFrameCache sharedSpriteFrameCache] removeUnusedSpriteFrames];
}
该通知未发布

self.fWalk = [[CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation:walk restoreOriginalFrame:NO]] retain];
CCAnimation *anim = [CCAnimation animationWithSpriteFrames:animFrames delay:pDelay];
CCAnimate *animate = [CCAnimate actionWithAnimation:anim];
CCCallFunc *callback = [CCCallFunc actionWithTarget:pTarget selector:pCallBack];
CCSequence *seq = [CCSequence actions:animate, callback , nil];

NSMutableDictionary *animations;

[animations setValue:seq forKey:pName];

- (void)dealloc {
    for (NSString* key in [animations allKeys]) {
        CCAction *action = [animations objectForKey:key];
        [self stopAction:action];
        [action stop];
    }

    [animations removeAllObjects];
    //[[CCSpriteFrameCache sharedSpriteFrameCache] removeUnusedSpriteFrames];
}