我使用ARC与iOS SDK 6.0。
我敢肯定我有这林有麻烦跟踪了一些内存泄漏。
运行静态分析后,即时获取有关以下两种方法警告:
+ (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,以便能够处理自动引用计数。
任何帮助将非常感激。