Analyzer报告以下代码存在潜在的内存泄漏。有谁能解释一下这件事吗?我正在释放已分配的注释。
-(AddressAnnotation *)addAdress:(NSString*)placeTitle SubTitle:(NSString*)placeSubTitle Coordinate:(CLLocationCoordinate2D)coord withId:(NSInteger) placeId{
AddressAnnotation *annotation = [[AddressAnnotation alloc] initWithCoordinate:coord];
annotation.placeTitle = placeTitle;
annotation.placeSubTitle = placeSubTitle;
annotation.museumId = placeId;
[mapView addAnnotation:annotation];
return annotation;
[annotation release];
}发布于 2012-05-24 23:40:21
变化
return annotation;
[annotation release];至
return [annotation autorelease];发布于 2012-05-24 23:39:37
你是在返回后释放的,所以永远不会被调用。另请注意,当您添加地图视图时,它会保留注释。
https://stackoverflow.com/questions/10740721
复制相似问题