2011-01-25 10 views
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 remove:]가 호출되는 동안 [MKQuadTrie insert:]가 두 번 호출되는 것 같다. 무언가와 그 잘못을 놓치고 있거나 MKMapKit의 버그입니까?

편집 : 나는 14 할당 연혁을 보았다 [MKQuadTrie 삽입 :] 통화 만 1 MKQuadTrie 제거 :]

답변

5

내가

내가 모든를 제거하려고했던 나를 위해이 문제를 해결 확인 주석을 추가하고 새 코드를 추가하십시오 (그러나 코드는 사용자 위치를 제거하지 못하도록합니다). 내가이

[self.map removeAnnotations: [self.map.annotations filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"!(self isKindOfClass: %@)", [MKUserLocation class]]]]; 

로 교체 그리고 지금 같은 문제가하지 않는 코드

함께 할 수있는 뭔가했다.

+0

글쎄 지금은이 시간을 들여다 볼 시간이 없지만 생각해 보면 그 문제를 해결할 수있는 유일한 방법은 문제를 해결할 수 있다는 것입니다. (실제로 모든 주석을 자신의 배열에 넣지 않는 한 'removeAnnotiations :'에 건네 준다),'map.annotations'에는 몇 차례의 주석이 여러 번 포함되어있어,'removeAnnotations :'는 전달한 주석의 최초의 출현 만 제거합니다. 따라서'[map removeAnnotations : map.annotations]'는 작동합니다 왜냐하면 당신은 여러 번 발생하는 배열을 전달하기 때문입니다. 답장을 보내 주셔서 감사합니다. –

관련 문제