开发者

Leak on a NSString that's released

I'm finishing my app and it's time to fix all the leaks, so I use Instruments.

Here's the code and the leak...

- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
    [connection release];

    NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
    [responseData release];
    //NSString *responseString2 = [NSString stringWithFormat:@"%s%@%s", "[", responseString, "]"]; 
    // Pour ajouter les [] si y'en a pas autour de tout le contenu JSON, et on doit utiliser responseString2 au lieu de responseString à la ligne ci-dessous
    NSArray *tableau = [responseString JSONValue];
    [responseSt开发者_StackOverflow社区ring release];
    NSDictionary *dico = [tableau objectAtIndex:0];

It is responseString that leaks BUT I release it after put this value in the array... How can I delete the leak? I don't understand my mistake.


Leaks is showing you where the leak was allocated, not where it was actually leaked; not the extra retain that is causing the problem.

Use the Allocations instrument to track all the retain/release calls on the object and find the extra retain. That'll be your leak.


My explanation of how to do Heapshot based analysis should help you (as it can be used to track down problems exactly like this, too).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜