我有以下简单的代码来跟踪MKMapView中的MKAnnotations。我通过我想跟踪的位置列表循环创建注释。我将注释添加到我的集合类,一个NSMutableDictionary和NSMutableArray,这些属性被声明为属性(不是使用ARC,而是使用Xcode 4.2,所以使用“strong”而不是retain,因为它们被认为是同义词,以便与ARC兼容)。iOS:Xcode 4.2:泄漏仪器说我有我的NSMutableArray和NSMutableDictionary泄漏,但我看不到在哪里
如果我第二次调用这个例程(比如当位置列表被更新时),泄漏工具声称注释泄漏以及集合对象本身。 (我的泄漏列表中有一个NSMUtableDictionary,堆栈跟踪指向创建字典的行,并将其设置到我的属性中,我们以及一些与注释相匹配的小型泄漏,以及有关NSMutableArray和NSMutableDictionary)。但是,我没有看到任何违反内存管理规则的行为。我通过alloc/init创建了一个与我的注释创建配对的发行版。我通过我的属性“setter”做了隐式保留,当集合被替换时,它们应该被释放,然后释放它们的所有内容对象。如果有人能看到我出错的地方,我会很感激。
@property(strong, nonatomic) NSMutableArray *annotationList;
@property(strong, nonatomic) NSMutableDictionary *annotationLocations;
。
-(void) createMapAnnotations
{
if ([[self mapView] annotations])
[[self mapView] removeAnnotations:[[self mapView] annotations]];
[self setAnnotationList:[NSMutableArray array]];
[self setAnnotationLocations:[NSMutableDictionary dictionary]];
for (JEstablishmentLocation *loc in [[JLocationManager sharedLocationManager] localLocations])
{
MKPointAnnotation *annotation = [[MKPointAnnotation alloc] init];
[annotation setCoordinate:[[loc estCoordinates] coordinate]];
[[self mapView] addAnnotation:annotation];
[[self annotationList] addObject:[NSDictionary dictionaryWithObject:annotation forKey:[loc estKeyValue]]];
[[self annotationLocations] setObject:loc forKey:[annotation description]];
[annotation release];
}
[self centerOnCurrentLocation];
}
你有没有尝试清除你的数组和字典之前'失去'他们?乍一看你的代码似乎很好。 – jv42 2012-01-18 08:34:33
尽管有语义上的等价性,但与保留的交流仍然很强烈,仪器是否仍然显示泄漏?这不是一个ARC代码,你确实在dealloc中释放了两个ivars,不是吗? – 2012-01-18 14:11:25
我会尝试交换强/保留。是的,ivars是在dealloc中释放的,但是控制器对象并没有死掉,所以永远不会被调用。 – chadbag 2012-01-18 16:34:00