I am using ARC with ios sdk 6.0.
I am pretty sure I have got some memory leaks which Im having trouble tracking down.
After running the static analyser, im getting warnings about the following two methods:
+ (id<MXURLRequest>) requestWithURL:(NSURL*)url {
MXASIURLRequest *request = [[MXASIURLRequest alloc] init];
[request setUrl:url];
return request; // STATIC ANALYSER: Potential leak of an object stored into 'request'
}
- (id)parseBody:(NSError *)error {
NSString *contentType = [[_request responseHeaders] objectForKey:@"Content-Type"];
id body = nil;
if ([contentType hasPrefix:@"application/json"] ||
[contentType hasPrefix:@"text/json"] ||
[contentType hasPrefix:@"application/javascript"] ||
[contentType hasPrefix:@"text/javascript"]) {
body = [NSJSONSerialization JSONObjectWithData:[_request responseData] options:NSJSONReadingMutableLeaves error:&error];
} else if ([contentType hasPrefix:@"image/"] ||
[contentType hasPrefix:@"audio/"] ||
[contentType hasPrefix:@"application/octet-stream"]) {
body = [_request responseData];
} else {
body = [[NSString alloc] initWithData:[_request responseData] encoding:NSUTF8StringEncoding];
}
return body; // STATIC ANALYSER : Potential leak of an object stored into 'body'
}
The warnings are as follows...
Object leaked: object allocated and stored into 'request' is returned from a method
whose name ('requestWithURL:') does not start with 'copy', 'mutableCopy', 'alloc'
or 'new'. This violates the naming convention rules given in the Memory Management
Guide for Cocoa
Object leaked: object allocated and stored into 'body' is returned from a method
whose name ('parseBody:') does not start with 'copy', 'mutableCopy', 'alloc' or
'new'. This violates the naming convention rules given in the Memory Management
Guide for Cocoa
Can anyone see what I've done wrong here? Are these warnings legitimate, or can they be ignored? To me these methods look valid for ARC to be able to handle automatic reference counting.
Any help would be much appreciated.