everytime I call this method 2 NSString and 1 NSMutableArray objects leak, which is disgusting, because i’m using it a lot in my app.
Here’s the method:
+ (NSString *)queryStringFromParameters:(NSDictionary *)parameters {
NSMutableArray __block *entries = [[NSMutableArray alloc] init];
[parameters enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
NSString *entry = [NSString stringWithFormat:@"%@=%@", [key pcen], [obj pcen]];
[entries addObject:entry];
}];
return [entries componentsJoinedByString:@"&"];
}
Here is the [pcen] method
- (NSString *)pcen {
CFStringRef string = CFURLCreateStringByAddingPercentEscapes(NULL,
(CFStringRef)self,
NULL,
CFSTR("!*'();:@&=+$,/?%#[]"),
kCFStringEncodingUTF8);
return [(NSString *)string autorelease];
}
They are in the same file, my project is ARC, but for this file I unchecked ARC.
Why this leak happens every time I try to use it?
Thank you!
You do not release the
entriesarray.And btw, the
__blockmodifier is not necessary here, because you do not modify that variable inside the block.