2012-01-18 68 views
1

我有以下簡單的代碼來跟蹤MKMapView中的MKAnnotations。我通過我想跟蹤的位置列表循環創建註釋。我將註釋添加到我的集合類,一個NSMutableDictionary和NSMutableArray,這些屬性被聲明爲屬性(不是使用ARC,而是使用Xcode 4.2,所以使用「strong」而不是retain,因爲它們被認爲是同義詞,以便與ARC兼容)。iOS:Xcode 4.2:泄漏儀器說我有我的NSMutableArray和NSMutableDictionary泄漏,但我看不到在哪裏

如果我第二次調用這個例程(比如當位置列表被更新時),泄漏工具聲稱註釋泄漏以及集合對象本身。 (我的泄漏列表中有一個NSMUtableDictionary,堆棧跟蹤指向創建字典的行,並將其設置到我的屬性中,我們以及一些與註釋相匹配的小型泄漏,以及有關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]; 
} 
+0

你有沒有嘗試清除你的數組和字典之前'失去'他們?乍一看你的代碼似乎很好。 – jv42 2012-01-18 08:34:33

+0

儘管有語義上的等價性,但與保留的交流仍然很強烈,儀器是否仍然顯示泄漏?這不是一個ARC代碼,你確實在dealloc中釋放了兩個ivars,不是嗎? – 2012-01-18 14:11:25

+0

我會嘗試交換強/保留。是的,ivars是在dealloc中釋放的,但是控制器對象並沒有死掉,所以永遠不會被調用。 – chadbag 2012-01-18 16:34:00

回答

0

儀器顯示泄漏對象的分配位置,它不顯示泄漏發生的位置。我的意思是,也許是在指向線上分配的對象,導致代碼中的其他位置發生泄漏。

雖然我不知道這可能是你的代碼的情況。

+0

是的。就我而言,沒有其他地方可以處理任何這些物體。他們只是從這個課程的其他地方讀取(這是他們被引用的唯一地方)。我開始認爲這是一場虛驚。作爲參考,靜態分析顯示此代碼沒有問題。 – chadbag 2012-01-18 08:54:26

+0

清理所有輸出和重建後,您正在分析代碼,對吧? – aslisabanci 2012-01-18 09:07:46

+0

是的,我正在那樣做。 – chadbag 2012-01-18 09:18:40