簡體   English   中英

iOS:Xcode 4.2:Leaks Instrument說我的NSMutableArray和NSMutableDictionary泄漏了,但我看不到哪里

[英]iOS: Xcode 4.2: Leaks Instrument says I have a leak with my NSMutableArray and NSMutableDictionary but I don't see where

我有以下簡單的代碼來跟蹤我的MKMapView中的MKAnnotations。 我在要跟蹤的位置列表中循環創建注釋。 我將注釋添加到我的集合類NSMutableDictionary和NSMutableArray中,它們被聲明為屬性(不使用ARC,而是使用Xcode 4.2,因此使用“ strong”而不是保留,因為它們被認為是同義詞;為了將來與ARC兼容)。

如果我第二次調用此例程(例如更新位置列表時),則泄漏工具聲稱注釋以及集合對象本身在泄漏。 (我在泄漏列表中得到了一個N​​SMUtableDictionary,其中堆棧跟蹤指向創建字典並將其設置到我的屬性的行,還有一些與注釋匹配的小泄漏,以及對NSMutableArray的抱怨和NSMutableDictionary)。 但是,我看不到任何違反內存管理規則的行為。 我有一個發布和通過alloc / init創建的注釋配對。 我通過屬性“ setter”進行隱式保留,當替換集合時,應該釋放它們,然后釋放所有內容對象。 如果有人看到我出了問題,我將不勝感激。

@property(strong, nonatomic) NSMutableArray *annotationList;
@property(strong, nonatomic) NSMutableDictionary *annotationLocations; 

-(void) createMapAnnotations
{      
     if ([[self mapView] annotations])
        [[self mapView] removeAnnotations:[[self mapView] annotations]];

     [self setAnnotationList:[NSMutableArray array]];
     [self setAnnotationLocations:[NSMutableDictionary dictionary]];

     for (JEstablishmentLocation *loc in [[JLocationManager sharedLocationManager] localLocations])
        {
          MKPointAnnotation *annotation = [[MKPointAnnotation alloc] init];
          [annotation setCoordinate:[[loc estCoordinates] coordinate]];

          [[self mapView] addAnnotation:annotation];
          [[self annotationList] addObject:[NSDictionary dictionaryWithObject:annotation forKey:[loc estKeyValue]]];
          [[self annotationLocations] setObject:loc forKey:[annotation description]];

          [annotation release];
          }
     [self centerOnCurrentLocation];
}

儀器顯示泄漏對象的分配位置,而不顯示泄漏發生的位置。 我的意思是,也許分配給該指針的對象在代碼中的其他地方引起泄漏。

不過,我不知道您的代碼是否可能是這種情況。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM