2011-07-26 55 views
1

我從這段代碼中得到一個泄露的NSCFString。我知道它與NSString有關,但我不明白泄漏是如何發生的。感謝您的幫助提前...基金會NSCFString中的內存泄漏。 NSString創建和發佈。仍然泄漏

-(void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark{ 

    NSString *pTitle = [[NSString alloc] initWithString:placemark.title]; 

    mapView.userLocation.title = pTitle; 
    [pTitle release]; 


} 
+0

你是否檢查儀器上的泄漏? – Hisenberg

+0

是的,我正在運行一個設備並檢查儀器中的泄漏 – iOSDevSF

回答

3

您是否還泄漏地圖視圖?在這種情況下,這個字符串的報告泄漏只是通過擴展泄漏的地圖視圖。

大多數情況下最泄漏對象不是罪魁禍首。罪魁禍首通常是一個持有十幾個最泄漏對象的單個對象。

此外,您可以將代碼削減到:

-(void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark { 
    mapView.userLocaltion.title = placemark.title; 
} 

無需不需要的時候做的內存管理:)。

+0

我更改了我的代碼並檢查了我的mapView版本。但泄漏現在仍然存在,現在它來自MapKit。 我將屬性設置爲零,並在dealloc中釋放iVar。 - (void)viewDidUnload {super viewDidUnload]; \t self.mapView = nil;} - (void)dealloc {0} {0} {0} {_mapView release}; [super dealloc];} – iOSDevSF

+0

@ SteveBay22 - 此漏洞也存在於蘋果的框架中,它不時發生。仔細檢查,並提交bug http://report.apple.com – PeyloW

+0

不需要做內存管理,當不需要:)。! –

0

蘋果的框架夥伴中有很多錯誤..不要擔心從框架泄漏。

只要按照你身邊的規則。對於每個alloc,copyretain,必須有相應的release

另外iOS以一種完全不同的方式處理NSString ..所以最好遵守規則。

希望它有幫助..