سؤال

I am using following code to parse JSON and getting memory leak (100%) on line number 2. I don't know what is the problem, can someone help me ?

    NSString *response = [request responseString];
    NSMutableDictionary *responseJSON = [response JSONValue]; (100% leak)

    NSString *tockenString = [responseJSON objectForKey:@"Token"];
    NSString *userIDString = [responseJSON objectForKey:@"ID"];
هل كانت مفيدة؟

المحلول

I found the answer. Go to SBJsonParser.m function scanRestOfString and change the line

from

        *o = [[NSMutableString alloc] initWithBytes:(char*)c length:len encoding:NSUTF8StringEncoding];

to

        *o = [[[NSMutableString alloc] initWithBytes:(char*)c length:len encoding:NSUTF8StringEncoding] autorelease];

SBJsonParser has a like in scanRestOfString/NSMutableString. I reported the bug as well. Thank you all.

نصائح أخرى

Remove those 2 autoreleases. They overrelease the objects.

I've had a similar problem but it turned out the leak was actually higher in the chain of methods, but Instruments was (mistakenly) pointing to this line. Look at the methods that store the results retrieved from this code.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top