问题一
Place *place = [[[Place alloc] initwithCoordinate:location anotationType:CSMapAnnotationTypeStart] autorealease];
place.name = name;
place.description = description;
place.strUniqueIdentity = uniqueIdentity;
NSLog(@"Unique identity %@",uniqueIdentity);
PlaceMark *marker = [[PlaceMark alloc] initWithPlace:place annotationType:MapAnnotationTypePin];
return [marker autorelease];
当我分析 xcode 4.6.2 中的代码时,它在倒数第二行显示“对象发送 - 自动释放太多次”。 我不明白为什么会这样显示。
问题 2:
return [[[OAProblem alloc] initWithResponseBody:response] autorelease];
在这一行中,它显示“存储在‘self’中的对象的潜在泄漏”。
最佳答案
Why are you not using Arc?
的答案完全无效。 OP 特别询问为什么会在他自己的环境中发生这种情况。所以:
你能告诉我们你的:
Place *place = [[Place alloc] initwithCoordinate:location anotationType:CSMapAnnotationTypeStart];
同时使用仪器,看看您的项目是否存在问题。并非静态分析器显示的所有内容实际上都是问题。可能会出现一些误报。
因此从您的回复中可以得到:
-(id)initwithCoordinate:(CLLocationCoordinate2D)coordinate anotationType:(CSMapAnnotationType)anotationType{
self.latitude = coordinate.latitude;
self.longitude = coordinate.longitude;
self.mapAnnotationType = anotationType;
return self;
}
应该是这样的:
-(id)initwithCoordinate:(CLLocationCoordinate2D)coordinate anotationType:(CSMapAnnotationType)anotationType{
if (self = [super init])
{
self.latitude = coordinate.latitude;
self.longitude = coordinate.longitude;
self.mapAnnotationType = anotationType;
}
return self;
}
这就是他提示保留计数 == 0 的对象的原因。
关于iphone - 内存管理困惑 Objective C,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16163178/