2012-01-05 7 views
4

VCN1이 VC2를 탐색 스택에 밀어 넣는 내비게이션 컨트롤러가 있습니다. VC2는 사용자 위치가 설정된 탭 기반보기에서 MKMapView를가집니다. Heapshot Analysis 도구를 사용하여 계측기를 사용하여 반복 할당을 검사 할 때 VC1로 다시 돌아올 때 일부 MKUserLocation 개체가 할당 취소되지 않는 것을 반복적으로 찾습니다. enter image description hereMKMapView가 MKUserLocation의 메모리를 할당 해제하지 않습니다.

dealloc에서 모든 주석을 제거했으며 사용자 위치를 비활성화했습니다. 이 힙이 성장한 이유는 무엇일까요? VC2에서

- (NSIndexPath *)tableView:(UITableView *)tableView 
    willSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
    VC2 *vc2 = [[VC2 alloc] init]; 
    vc2.index = indexPath.row; 
    [[NSNotificationCenter defaultCenter] removeObserver:self]; 
    [[self navigationController] pushViewController:vc2 
              animated:YES]; 
    [vc2 release]; 
    vc2 = nil; 
    return nil; 
} 

의 dealloc 코드 : 탐색 스택에 VC2를 밀어

VC1 코드 내가 할 경우

- (void)dealloc { 
//Other UILabel, UITextField objects dealloc methods go here 
//The next four lines of code do not make a difference even if they are in viewWillDisappear 
[self.mapView removeAnnotations:self.mapView.annotations]; 
[self.mapView.layer removeAllAnimations]; 
self.mapView.showsUserLocation = NO;//This line does not make a difference in heapshot 
mapView.delegate = nil; 
[mapView release]; 
mapView = nil; 
[super dealloc]; 

} 또한

는 더 힙 성장도 없다 사용자 위치를 켜지 마십시오.

업데이트 : 나는 시뮬레이터와 iPad 3G + WiFi에서 이것을 테스트했으며 두 경우 모두이 힙 성장을 발견했습니다.

+0

실제로 VC2에서 dealloc가 호출됩니까? – Anna

+0

예, 다른 모든 개체는 할당이 해제됩니다. 나는 다른 객체에 대해 dealloc을 꺼내서 검사했고 힙샷에 나타나기 시작했습니다. –

+0

VC2 dealloc 메서드와 VC2를 생성하고이를 푸시하는 코드를 게시 할 수 있습니까? 사용자 위치를 끄고지도 위임을 VC2의 viewWillDisappear에서 nil로 설정해 보았습니까? – Anna

답변

5

IB에서 MKMapView을 만드는 경우/nil-viewDidUnload-dealloc으로 출시해야합니다.

보기 컨트롤러를 만료 한 상태에서보기를 언로드하거나 다시로드하면 유지 된 속성으로 설정된 모든보기 요소가 다시로드되어 누출됩니다.

Web/SO에는 이것이 5.0.1 이전의 API 버그라고 말하는 상당한 양의 대화가있는 것으로 보입니다. 어떤 버전의 SDK를 사용하고 있습니까?

또한, 어두운 곳에서 촬영 : 단지

self.mapView.showsUserLocation = NO; 

또는

self.mapView.showsUserLocation = NO; 
[self.mapView.layer removeAllAnimations]; 
[self.mapView removeAnnotations:self.mapView.annotations]; 

대신 당신이 지금 사용하고있는 이러한 명령의 순서

보십시오.

MKUserLocation에 대한 특수 효과를 제거하기 전에 MKMapView에 올바르게 특수 효과를 적용 할 수 있나요?

+0

viewDidUnload 및 dealloc에서 해제하려고 시도했지만 여전히 동일한 문제가 있습니다. –

+0

두 방법 모두 시도했지만 다중 할당 문제를 변경하지 않았습니다. 나는 최신 SDK 5.0.1을 사용 중이므로, 테스트 한 장치도 마찬가지다. –

관련 문제