NSArray* excludeActivity 即使在使用 ARC 并将其设置为 nil 时也会泄漏内存 [英] NSArray* excludedActivities Leaks memory even when using ARC and setting it to nil

查看:40
本文介绍了NSArray* excludeActivity 即使在使用 ARC 并将其设置为 nil 时也会泄漏内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用新的 iOS6 UIActivityViewController 并且它工作正常,除了内存泄漏工具说每次我尝试显示控制器时 NSArray *excludedActivities 都在泄漏.

I'm trying to use the new iOS6 UIActivityViewController and it works fine except that the Memory Leaks instrument says that the NSArray *execludedActivities is leaking every time I try to show the controller.

请注意,我尝试使用名为 excludeActivities 的 NSArray,然后将 shareShareController.excludedActivityTypes 设置为能够稍后将数组设置为 nil(所有这些都是下面注释的代码),但现在我正在直接设置该属性并且仍然存在是泄漏.

Note that I tried to use an NSArray called excludedActivities and then set the shareShareController.excludedActivityTypes to be able to set the array to nil later (all that is commented code below) but now I'm setting the property directly and still there is a leak.

- (IBAction)share:(id)sender
{

    //prepare the image
    UIImage *theImage = [self screenShot];

    //The array of activity Items
    NSArray *activityItems = [[NSArray alloc] initWithObjects:theImage, nil];


   //The acitivyViewController
   UIActivityViewController *shareController = [[UIActivityViewController alloc]   initWithActivityItems:activityItems applicationActivities:nil];

//Excluded Actvivity Types
//NSArray *excludedAcitivities = [[NSArray alloc]   initWithObjects:UIActivityTypeAssignToContact,UIActivityTypeCopyToPasteboard,UIActivityTypePostToWeibo, UIActivityTypePrint, nil];

shareController.excludedActivityTypes = [[NSArray alloc] initWithObjects:UIActivityTypeAssignToContact,UIActivityTypeCopyToPasteboard,UIActivityTypePostToWeibo, UIActivityTypePrint, nil];

    //testing fixning the leak of NSArray
    //excludedAcitivities = nil;

    //set the completion handler
    [shareController setCompletionHandler:^(NSString *activityType, BOOL completed) {

        //test hiding the By MunasabaPro lable
        int shareScreen = pageControl.currentPage;
        MainViewController *someController = [viewControllers objectAtIndex:shareScreen];
        someController.byLabel.hidden = YES;
    }];

    [self presentViewController:shareController animated:YES completion:nil];
}

推荐答案

我认为您的完成处理程序中有一个保留周期.看看那个问题.

I think you have a retain cycle in your completion handler. Take a look at that question.

__weak id blockShareController = shareController;
[shareController setCompletionHandler:^(NSString *activityType, BOOL completed) {

       //test hiding the By MunasabaPro lable
        int shareScreen = pageControl.currentPage;
        blockShareController.byLabel.hidden = YES;
    }];

这篇关于NSArray* excludeActivity 即使在使用 ARC 并将其设置为 nil 时也会泄漏内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆