ios - 分配对象的潜在泄漏

标签 ios memory-leaks cocos2d-iphone

分析我的 cocos2d 游戏后,我在这段代码中收到警告“第 525 行分配并存储到‘valueString’中的对象的潜在泄漏”

525  NSString * valueString=[[[NSString alloc] initWithString:[NSString stringWithFormat:@"%@: %@",kGameTimeeng,[allFunctions getTimeFormat:(int) _timeLimit]]] retain];

    if([_language isEqualToString:@"rus"]){
        [valueString release];
        valueString=[[[NSString alloc] initWithString:[NSString stringWithFormat:@"%@: %@",kGameTimerus,[allFunctions getTimeFormat:(int) _timeLimit]]] retain];
    }    

    id sequence=[CCSequence actions:
                 [CCCallFuncND actionWithTarget: allFunctions selector: @selector(setLabelColor:withIndex:) data:(void*)color],
                 [CCCallFuncND actionWithTarget: allFunctions selector: @selector(setLabelValue:withValue:) data:(NSString*)valueString],
                // [CCCallFuncND actionWithTarget: self selector: @selector(setLabelStroke:withTag:) data:(void*)TagCurentPointsLabelStroke],
                 [CCBlink actionWithDuration:0.5f blinks:2],
                 [CCShow action], 
                 [CCCallFuncND actionWithTarget: allFunctions selector: @selector(setLabelColor:withIndex:) data:(void*)colorAfter],

                 nil];

    [_timeLimitLabel runAction:sequence];
    [valueString release];

allFunctions.m

-(void) setLabelValue:(id) sender withValue:(NSString*) value
{   
    CCLabelTTF *label=(CCLabelTTF *)sender;
    NSString * valueString=[[[NSString alloc] initWithString:[NSString stringWithFormat:@"%@",value]] autorelease];
    [label setString:[NSString stringWithFormat:@"%@",valueString]];
   //[valueString release];
}

你能解释一下为什么吗?

最佳答案

525 if([_language isEqualToString:@"rus"]){
        [valueString release];
        valueString=[[[NSString alloc] initWithString:[NSString stringWithFormat:@"%@: %@",kGameTimerus,[allFunctions getTimeFormat:(int) _timeLimit]]] autorelease];
    } else {    
        NSString * valueString=[[[NSString alloc] initWithString:[NSString stringWithFormat:@"%@: %@",kGameTimeeng,[allFunctions getTimeFormat:(int) _timeLimit]]] autorelease];
    }


    id sequence=[CCSequence actions:
                 [CCCallFuncND actionWithTarget: allFunctions selector: @selector(setLabelColor:withIndex:) data:(void*)color],
                 [CCCallFuncND actionWithTarget: allFunctions selector: @selector(setLabelValue:withValue:) data:(NSString*)valueString],
                // [CCCallFuncND actionWithTarget: self selector: @selector(setLabelStroke:withTag:) data:(void*)TagCurentPointsLabelStroke],
                 [CCBlink actionWithDuration:0.5f blinks:2],
                 [CCShow action], 
                 [CCCallFuncND actionWithTarget: allFunctions selector: @selector(setLabelColor:withIndex:) data:(void*)colorAfter],

                 nil];

    [_timeLimitLabel runAction:sequence];

关于ios - 分配对象的潜在泄漏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11627872/

相关文章:

xml泄漏内存中的Android位图?

c++ - 堆栈展开是否会释放在堆上分配的内存?

ios - 检查背景音乐是​​否已经在播放

ios - 该应用程序未在 iPhone 上全屏显示,但在模拟器上运行良好

android - 如何检索我的应用程序的源代码

ios - 午睡休息登录

c++ - 需要手动删除 QValidator 吗?

cocos2d-iphone - 从头开始构建 2D 游戏引擎或学习 Cocos 2D

cocos2d-iphone - 在 cocos2d 中处理游戏循环

ios - 如何更改 CAShapeLayer alpha/opacity 值?