English 中文(简体)
这怎么不是记忆漏漏?
原标题:How is this NOT a Memory Leak

我试图找出以下方法是如何导致内存泄漏的。 分配了一个 < code> UIPopover 主计长 < / code >, 但是, 如果我包括一个 < code> autorelease 或 < code> release 呼叫, 应用程序崩溃, 消息 < code > - [UIPopover 主计长事务 仍然可见, 到达时仍然可以看到 。 < / code >

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

这似乎违背了基本的记忆管理做法。

p. s. 我还没有启用 ARC 。

最佳回答

这还是一个记忆泄漏!

You have to keep a reference to the popover controller in your class and/or implement the delegate method popoverControllerDidDismissPopover: (you can release it there).
A popover controller does not retain itself when you call its "present..."-methods and throws an exception if it is deallocated and still visible

问题回答

UIPopover 主计长

- (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController method and do the following.

- (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController {

    if(popoverController == yourPopoverController)

    {

            [popoverController release];

    }

}




相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签