2
我收到我的注释泄漏。该代码有问题(剥离下来到其承受的最低)是:当删除注解或只是我时,MKMapView泄漏?
- (void)updateLocations:(NSArray *)result {
[mapView removeAnnotations:locations];
[locations removeAllObjects];
[allLocations removeAllObjects];
for (NSDictionary *location in result) {
LocationAnnotation *annote = [[LocationAnnotation alloc] initWithInfo:location];
[allLocations addObject:annote];
[annote release];
}
[self updateAnnotations];
}
- (void)filterLocations {
for (LocationAnnotation *annote in allLocations) {
if (annote.typeFlag & filterFlags) {
[locations addObject:annote];
}
}
}
- (void)updateAnnotations {
[self filterLocations];
[mapView addAnnotations:locations];
}
- (void)updateFilter {
[mapView removeAnnotations:locations];
[locations removeAllObjects];
[self updateAnnotations];
}
allLocations
是包含所有注释的数组(他们不一定在地图上),并且locations
是保存位置的数组实际上显示在地图上。当调用updateLocations:
时,添加到地图的注释中的一些(或全部,从测试变为测试)泄漏。注释的分配历史记录是:
# Category Event Type Timestamp RefCt Address Size Responsible Library Responsible Caller
0 LocationAnnotation Malloc 16421111296 1 0x4953870 64 MyApp -[MapViewController updateLocations:]
1 LocationAnnotation Retain 16421383424 2 0x4953870 0 MyApp -[MapViewController updateLocations:]
2 LocationAnnotation Release 16421391104 1 0x4953870 0 MyApp -[MapViewController updateLocations:]
3 LocationAnnotation Retain 16444210176 2 0x4953870 0 MyApp -[MapViewController filterLocations]
4 LocationAnnotation Retain 16557738240 3 0x4953870 0 MapKit -[MKQuadTrie insert:]
5 LocationAnnotation Retain 16557750272 4 0x4953870 0 MapKit -[MKAnnotationContainerView addAnnotation:]
6 LocationAnnotation Retain 16564529408 5 0x4953870 0 MapKit -[MKQuadTrie insert:]
7 LocationAnnotation Release 17296397312 4 0x4953870 0 MapKit -[MKAnnotationContainerView showAddedAnnotationsAnimated:]
8 LocationAnnotation Retain 21832317184 5 0x4953870 0 MapKit -[MKAnnotationContainerView removeAnnotation:]
9 LocationAnnotation Autorelease 21832324096 0x4953870 0 MapKit -[MKAnnotationContainerView removeAnnotation:]
10 LocationAnnotation Release 21832350208 4 0x4953870 0 MapKit -[MKQuadTrie remove:]
11 LocationAnnotation Release 21920062208 3 0x4953870 0 MyApp -[MapViewController updateLocations:]
12 LocationAnnotation Release 21923836416 2 0x4953870 0 MyApp -[MapViewController updateLocations:]
13 LocationAnnotation Release 22050286336 1 0x4953870 0 Foundation -[NSAutoreleasePool drain]
而且看着这似乎罪魁祸首是[MKQuadTrie insert:]
被调用了两次,而只有一个[MKQuadTrie remove:]
被调用。我错过了什么,它是我的错,还是它在MKMapKit中的错误?
编辑:我见过的分配histroy 14 [MKQuadTrie插入:]来电,但是仅1 MKQuadTrie删除:]
那么现在我没有时间研究这个问题,但考虑一下我唯一能想到的就是解决这个问题(除非你实际上没有在你自己的数组中包含所有的注释)你传递给`removeAnnotiations:`),就是`map.annotations`包含多次注释,`removeAnnotations:`只会删除你传入的第一批注释。因此`[map removeAnnotations:map.annotations]`作品因为你正在传递一个也有多个事件的数组。感谢您的回复,我会尽快研究它! – 2011-03-03 21:23:57