poi*_*ert 2 iphone memory-leaks mkmapview mkannotation
我正在泄漏我的注释.有问题的代码(剥离到最低限度)是:
- (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];
}
Run Code Online (Sandbox Code Playgroud)
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]
Run Code Online (Sandbox Code Playgroud)
看着这个,似乎罪魁祸首就是[MKQuadTrie insert:]被召唤两次,而只有一个[MKQuadTrie remove:]被召唤.我错过了什么,这是我的错,还是MKMapKit中的错误?
编辑:我看到一个分配histroy与14 [MKQuadTrie插入:]调用只有1 [MKQuadTrie删除:]
好吧,我为我解决了这个问题
我试图删除所有注释并添加新注释(但我的代码确保它没有删除用户位置).这与代码有关
我用它替换了它
[self.map removeAnnotations: [self.map.annotations filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"!(self isKindOfClass: %@)", [MKUserLocation class]]]];
Run Code Online (Sandbox Code Playgroud)
而现在我没有得到同样的问题.
| 归档时间: |
|
| 查看次数: |
1432 次 |
| 最近记录: |