开发者

Leaks on NSString that appendformats

I have lots of leaks on a NSString. I use appendformat to append strings to it.

Here's the code :

NSString *textedetails = [[NSMutableString alloc] init];
        if([dico objectForKey:@"alertSerie"] != nil)
            {[textedetails appendFormat:@"Numéro de Série: %@ \n",[dico objectForKey:@"alertSerie"]];}
        if([dico objectForKey:@"alertDate"] != nil)
            {[textedetails appendFormat:@"Date de mise en service: %@ \n",[dico objectForKey:@"alertDate"]];}
        if([dico objectForKey:@"alertCli"] !=开发者_StackOverflow中文版 nil)
            {[textedetails appendFormat:@"Nom du client associé: %@ \n",[dico objectForKey:@"alertCli"]];}

... //I put the textdetails into a UITextField and... [textedetails release];

That code give me leaks in the first and the last line of the code above...

and the printscreen of the leaks is HERE !!!

Many thanks to help me !!!


NSString *textedetails = [[NSMutableString alloc] init];
NSMutableString *texterecap = [[NSMutableString alloc] init];

both these are never released.

Try this

NSString *textedetails = [[[NSMutableString alloc] init] autorelease];
NSMutableString *texterecap = [[[NSMutableString alloc] init] autorelease]; 

or this

NSMutableString *textedetails = [NSMutableString string];
NSMutableString *texterecap = [NSMutableString string];


The method appendFormat is not directly leaking. It's just a subsequent fault because the NSMutableString instance is never released.

I see two locations where you create a NSMutableString instance with:

... = [[NSMutableString alloc] init];

These instance have to be release somewhere.


You can try to release variables "textedetails" and "texterecap" right after you finish it uses.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜