【发布时间】:2012-05-25 19:36:20
【问题描述】:
我试图弄清楚以下方法如何不导致内存泄漏。分配了一个UIPopoverController,但是,如果我包含一个autorelease 或release 调用,应用程序将崩溃,并显示消息'-[UIPopoverController dealloc] reached while popover is still visible.'。
-(void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control {
[mapView deselectAnnotation:view.annotation animated:TRUE];
if ( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ) {
UIViewController *con = [[UIViewController alloc] init];
UIPopoverController *poc = [[UIPopoverController alloc] initWithContentViewController:con];
[con release];
poc.popoverContentSize = CGSizeMake( 320, 320 );
[poc presentPopoverFromRect:view.bounds inView:view permittedArrowDirections:UIPopoverArrowDirectionAny animated:TRUE];
}
else {
; // TODO (miked): display stuff another way
}
}
这似乎违背了基本的内存管理实践。
附言我没有启用 ARC。
【问题讨论】:
-
好问题,但我认为上面的链接已经回答了。
-
@StilesCrisis 你说得对,但我搜索时它没有显示出来。
标签: objective-c ios memory-management