VC1 が VC2 をナビゲーション スタックにプッシュするナビゲーション コントローラーがあります。VC2 にはタブ ベースのビューの MKMapView があり、ユーザーの場所がオンになっています。ヒープショット分析ツールを使用して計測器で繰り返し割り当てを確認すると、VC1 に戻ったときに割り当てが解除されていない MKUserLocation オブジェクトが繰り返し見つかります。
すべての注釈を削除し、割り当て解除時にユーザーの場所も無効にしました。このヒープの増加の理由は何でしょうか?
VC2 をナビゲーション スタックにプッシュする VC1 コード:
- (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;
}
VC2 の割り当て解除コード:
- (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 でこれをテストしましたが、どちらの場合もこのヒープの増加が見られました。