VCN1이 VC2를 탐색 스택에 밀어 넣는 내비게이션 컨트롤러가 있습니다. VC2는 사용자 위치가 설정된 탭 기반보기에서 MKMapView를가집니다. Heapshot Analysis 도구를 사용하여 계측기를 사용하여 반복 할당을 검사 할 때 VC1로 다시 돌아올 때 일부 MKUserLocation 개체가 할당 취소되지 않는 것을 반복적으로 찾습니다. MKMapView가 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에서 이것을 테스트했으며 두 경우 모두이 힙 성장을 발견했습니다.
실제로 VC2에서 dealloc가 호출됩니까? – Anna
예, 다른 모든 개체는 할당이 해제됩니다. 나는 다른 객체에 대해 dealloc을 꺼내서 검사했고 힙샷에 나타나기 시작했습니다. –
VC2 dealloc 메서드와 VC2를 생성하고이를 푸시하는 코드를 게시 할 수 있습니까? 사용자 위치를 끄고지도 위임을 VC2의 viewWillDisappear에서 nil로 설정해 보았습니까? – Anna