4

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 でこれをテストしましたが、どちらの場合もこのヒープの増加が見られました。

4

1 に答える 1

5

IB でを作成している場合は、 ANDMKMapViewでリリース/ nil-ingする必要があります。-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

于 2012-01-17T09:22:13.417 に答える