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%;

有谁知道可能是什么问题?

4

3 回答 3

3

我想我在没有转换为 ARC 的情况下解决了类似的问题。我有一个导航控制器,我的 viewController 包含一个 mapView。加载视图时,我调用setRegion:myregion animated:YES. 如果我在动画完成之前单击“返回”,mapView 会在消息上引发“发送到已释放实例的[respondsToSelector:]消息”错误。我myMapView.delegate = nil在发布 myMapView 之前通过设置解决了这个问题。

于 2013-02-13T18:59:28.817 回答
1

考虑使用 ARC(自动引用计数)。Xcode 可以使用 Menu 几乎完全自动地转换您的项目"Edit" ➞ "Refactor" ➞ "Convert to Objective-C ARC…"。继续手动管理内存的原因很少。

您也可以尝试运行静态分析器(菜单"Product" ➞ "Analyze")。

于 2012-08-13T10:04:14.370 回答
0

我认为您遇到的问题是您在将 viewController 推送到视图后直接释放它。此外,如果您已经为 setCurrentBus(在 BusInfoViewController 中)完成了自己的实现,问题可能就在那里。

于 2012-08-13T10:43:21.463 回答