I get a crash in my app with the message " ... sent to deallocated instance at the address ...". So, I analyzed the app with zombie instruments and I've presented below a fragment of code which causes the crash. I haven't found yet a scenario which causes this error.
(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];
}
}
The analyzer tool gets 91.4% at the line [self.navigationController pushViewController:viewController animated:YES];
Does anyone know what might be the problem?
Consider using ARC (Automatic Reference Counting). Xcode can convert your project almost completely automatically with Menu "Edit" ➞ "Refactor" ➞ "Convert to Objective-C ARC…"
. There are only few reasons to keep managing memory manually.
You could also try running the static analyzer (Menu "Product" ➞ "Analyze"
).