views:

94

answers:

2

Hi, im trying to get data via

NSString *string = [NSString stringWithContentsOfURL: [NSURL URLWithString: url]];

everything works fine, but when I run it with performance tool, it finds leaks on this line.

Here is whole mehod I use:

- (NSMutableDictionary *) getOutputImagesData: (URLParserImagesData) data
{
    NSString *type = (data == URLParserImagesDataLatestImage) ? @"img" : @"size";

    NSString *url = [NSString stringWithFormat: @"%s%s%s", [URLParserSiteURLforCategories UTF8String], [URLParserType UTF8String], [type UTF8String]];

    //i get leaks here      
    NSString *string = [NSString stringWithContentsOfURL: [NSURL URLWithString: url]];
    NSArray *imagesTemp = [string componentsSeparatedByString: @","];
    NSMutableDictionary *outputImages = [NSMutableDictionary dictionary];
    for(NSString *img in imagesTemp)
    {
    NSArray *splitStrings = [img componentsSeparatedByString: @"="];

    if(data == URLParserImagesDataImagesCount)
    {
        NSNumber *integerValue = [NSNumber numberWithInt: [[splitStrings objectAtIndex:1] intValue]];
        [outputImages setObject: integerValue forKey: [splitStrings objectAtIndex:0]];
    }
    else
        [outputImages setObject: [splitStrings objectAtIndex:1] forKey: [splitStrings objectAtIndex:0]];
    }

    return outputImages;
}
A: 

There is nothing wrong in your code.

BobC
A: 

stringWithContentsOfURL: is deprecated. Try to use stringWithContentsOfURL:encoding:error: or stringWithContentsOfURL:usedEncoding:error: instead.

kovpas
Thank you, I did not know this.
Tankista