0

我刚刚在我的应用程序中发现了内存泄漏,但我不确定如何修复它。它涉及一个活动视图,用于共享从 rss 提要查看的当前文章的 url。我不确定为什么会发生泄漏。有什么想法或建议吗?iPhone 泄漏 iPad 泄漏

iPhone版本的问题方法是:

- (void) showMenu
{   
    NSURL *urlToShare = hackyURL;
    NSArray *activityItems = @[urlToShare];
    TUSafariActivity *activity = [[TUSafariActivity alloc] init];

    UIActivityViewController *activityVC = [[UIActivityViewController alloc]initWithActivityItems:activityItems applicationActivities:@[activity]];
    activityVC.excludedActivityTypes = @[UIActivityTypeAssignToContact, UIActivityTypePostToWeibo, UIActivityTypeSaveToCameraRoll];

    [self presentViewController:activityVC animated:TRUE completion:nil];
}

编辑:我通过将上面的代码更改为以下代码来修复 iPhone 泄漏:

__block UIActivityViewController *activityVC = [[UIActivityViewController alloc]initWithActivityItems:activityItems applicationActivities:@[activity]];
    activityVC.excludedActivityTypes = @[UIActivityTypeAssignToContact, UIActivityTypePostToWeibo, UIActivityTypeSaveToCameraRoll];

    [self presentViewController:activityVC animated:YES completion:^{activityVC.excludedActivityTypes = nil; activityVC = nil;}];

iPad 版本基本相同,只是它使用弹出框来显示活动视图。

- (void)showMenu
{    
    NSURL *urlToShare = hackyURL;
    NSArray *activityItems = @[urlToShare];
    TUSafariActivity *activity = [[TUSafariActivity alloc] init];

    UIActivityViewController *activityVC = [[UIActivityViewController alloc]initWithActivityItems:activityItems applicationActivities:@[activity]];
    activityVC.excludedActivityTypes = @[UIActivityTypeAssignToContact, UIActivityTypePostToWeibo, UIActivityTypeSaveToCameraRoll];

    if ([popover isPopoverVisible])
    {
        [popover dismissPopoverAnimated:YES];
        popover = nil;
    }
    else
    {
        self.popover = [[UIPopoverController alloc]initWithContentViewController:activityVC];
        [self.popover presentPopoverFromBarButtonItem:systemAction permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
    }

}
4

2 回答 2

0
 if ([self.popover isPopoverVisible])
    {
        [self.popover dismissPopoverAnimated:YES];
        self.popover = nil;
    }
    else
    {
        self.popover = [[UIPopoverController alloc]initWithContentViewController:activityVC];
        [self.popover presentPopoverFromBarButtonItem:systemAction permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
    }

希望它能解决您的问题。

于 2013-07-31T20:38:40.037 回答
0

我通过将上面的代码更改为以下代码来修复 iPhone 泄漏:

__block UIActivityViewController *activityVC = [[UIActivityViewController alloc]initWithActivityItems:activityItems applicationActivities:@[activity]];
    activityVC.excludedActivityTypes = @[UIActivityTypeAssignToContact, UIActivityTypePostToWeibo, UIActivityTypeSaveToCameraRoll];

    [self presentViewController:activityVC animated:YES completion:^{activityVC.excludedActivityTypes = nil; activityVC = nil;}];

但我不知道如何修复 iPad 上弹出框的泄漏。

于 2013-07-31T20:29:18.520 回答