2012-02-09 33 views
0

我發現內存泄漏,同時剖析我的應用程序內存泄漏,同時創造註解點

CustomAnnotation *annotationPoint = [[CustomAnnotation alloc] initWithLatitude:store.latitude longitude:store.longitude]; 

annotationPoint.titleLabel = store.name; 
annotationPoint.subtitleLabel = [NSString stringWithFormat:@"%dm", store.distance]; 
[annotationPoint setEvent:store]; 

[self.mapView addAnnotation:annotationPoint]; 
[annotationPoint release]; 

這是被指定爲泄漏和annotationPoint.subtitleLabel = [NSString stringWithFormat:@"%dm", store.distance];標有100%

我應該怎麼做才能解決這個問題?

+0

您是否在自定義註釋的dealloc函數中調用[subtitleLabel release]?如何定義屬性?分配?保留? – guitarflow 2012-02-09 23:36:46

+0

'[NSString stringWithFormat]'由NSString自動釋放。如果你沒有安裝autoreleasepool,NSString就會泄漏。 – guitarflow 2012-02-09 23:44:18

+0

@guitarflow第一個想法是正確的。我忘了在自定義註釋中發佈。謝謝。發佈一個解決方案,我會標記是正確的。乾杯 – Mikael 2012-02-09 23:49:50

回答

0

您是否在調用CustomAnnotation的dealloc函數中調用[subtitleLabel release]? 這樣就解決了問題,在這種情況下,

正如我上面寫的:[NSString stringWithFormat]返回一個自動釋放的對象。 這意味着你必須使用autoreleasepools來進行正確的內存管理。