gpt4 book ai didi

objective-c - 这怎么不是内存泄漏

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:49:54 25 4
gpt4 key购买 nike

我试图找出以下方法如何不会导致内存泄漏。 UIPopoverController 已分配,但是,如果我包含 autoreleaserelease 调用,应用程序会崩溃,并显示消息 '-[ UIPopoverController dealloc] 在 popover 仍然可见时到达。'

-(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。

最佳答案

这仍然是内存泄漏!

您必须在您的类中保留对 popover Controller 的引用和/或实现委托(delegate)方法 popoverControllerDidDismissPopover:(您可以在那里释放它)。
当你调用它的“present...”方法时,popover Controller 不会保留它自己,如果它被释放并且仍然可见,它会抛出一个异常

关于objective-c - 这怎么不是内存泄漏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10760402/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com