iOS SDK 6.0 で ARC を使用しています。
追跡に苦労しているメモリリークがいくつかあると確信しています。
静的アナライザーを実行した後、次の 2 つの方法に関する警告が表示されます。
+ (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'
}
警告は次のとおりです...
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
ここで私が間違ったことを誰かが見ることができますか? これらの警告は正当なものですか、それとも無視できますか? 私には、これらの方法は、ARC が自動参照カウントを処理できるように有効に見えます。
どんな助けでも大歓迎です。