2012-08-13 19 views
0

我的應用程序崩潰,消息「...發送到解除分配的實例的地址...」。所以,我用殭屍工具分析了應用程序,並在下面提供了導致崩潰的代碼片段。 我還沒有找到導致此錯誤的場景。發送到釋放實例的消息 - 使用殭屍進行分析

(void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control 
{ 
if ([view.annotation isKindOfClass:[MKUserLocation class]]) { 
} 
else { 
    CustomAnnotation *ann = (CustomAnnotation *) view.annotation; 
    if (ann.annotationType == BusAnnotationType) { 
     NSLog(@"accessory button tapped for annotation %@", view.annotation); 
     BusInfoViewController *viewController = [[BusInfoViewController alloc] initWithNibName:@"BusInfoViewController" bundle:nil]; 
     BusForStation *bus = [self getBusWithId:[(CustomAnnotation *)view.annotation ID]]; 
     viewController.currentBus = bus; 
     [self.navigationController pushViewController:viewController animated:YES]; 
     [viewController release]; 
    } 
} 

分析儀工具在[self.navigationController pushViewController:viewController animated:YES]處獲取91.4%;

有誰知道可能是什麼問題?

回答

1

考慮使用ARC(自動引用計數)。 Xcode可以使用菜單"Edit" ➞ "Refactor" ➞ "Convert to Objective-C ARC…"幾乎完全自動轉換您的項目。只有幾個原因需要手動管理內存。

您也可以嘗試運行靜態分析器(菜單"Product" ➞ "Analyze")。

+0

我針對的應用程序低於5.0,所以我不能使用ARC,對吧? – dorin 2012-08-13 10:06:21

+0

@Dorin ARC適用於iOS 4.0+。您只需使用其中一個最新的Xcode版本即可使用此功能。 – 2012-08-13 10:07:13

0

我認爲你遇到的問題是你將viewController推到視圖後直接釋放。另外,如果你已經爲setCurrentBus(在BusInfoViewController中)完成了你自己的實現,問題可能就在那裏。

3

我想我解決了一個類似的問題,而不轉換爲ARC。我有一個navigationController與我的viewController包含一個mapView。當視圖加載時,我打電話給setRegion:myregion animated:YES。如果在動畫完成之前單擊「返回」,mapView會在[respondsToSelector:]消息中引發「發送到解除分配的實例的消息」錯誤。我在發佈myMapView之前通過設置myMapView.delegate = nil來解決這個問題。

相關問題