NSJSONSerialization泄漏 - 无法弄清楚为什么?

时间:2013-05-20 17:28:55

标签: iphone objective-c ipad

这是我的方法:

-(NSString *) getTemplateNamed: (NSString *) aTemplateName withManufacturerID: (NSNumber *) aManufacturerID withPriceLevel: (NSNumber *) aPriceLevel {
    @try {

        NSFetchRequest *request = [[NSFetchRequest alloc] init];
        [request setEntity:[NSEntityDescription entityForName:@"Manufacturer" inManagedObjectContext:self.managedObjectContext]];
        [request setPredicate:[NSPredicate predicateWithFormat:@"ManufacturerID==%@", aManufacturerID]];
        [request setFetchLimit:1];
        NSError *err=nil;
        NSArray *entities = [self.managedObjectContext executeFetchRequest:request error:&err];
        request=nil;

        NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:[[[entities lastObject] ManufacturerSettingsString] dataUsingEncoding:NSUTF8StringEncoding] options:kNilOptions error:nil];
        NSString *akey = [NSString stringWithFormat: @"PriceLevel%@", aPriceLevel ];
        if ([aPriceLevel isEqualToNumber:[NSNumber numberWithInt:0]]) {   akey=@"BasePrice"; }

        NSString *template = [dictionary valueForKey:aTemplateName];
        NSString *output = [template stringByReplacingOccurrencesOfString:@"Price" withString:[NSString stringWithFormat:@"%@Formatted", akey]];

        return  output;
    }
    @catch (NSException *exception) {
        return @"";
    }
}

根据Profiler,这是违规行:

 NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:[[[entities lastObject] ManufacturerSettingsString] dataUsingEncoding:NSUTF8StringEncoding] options:kNilOptions error:nil];

看起来NSJSONSerialization导致问题 - 任何想法?

0 个答案:

没有答案