0

I have isolated a memory leak to the setExcludedActivityTypes array. See code below:

- (void)postToFacebook:(UITapGestureRecognizer *)sender
{
    NSString *postText = socialString;
    UIImage *imageToPost = [self captureTheScreenImage];
    NSArray *postItems = @[postText, imageToPost];

    UIActivityViewController *activityPostVC = [[UIActivityViewController alloc]initWithActivityItems:postItems applicationActivities:nil];


    //NSArray *excludedItems = @[UIActivityTypePostToWeibo,UIActivityTypePrint,UIActivityTypeCopyToPasteboard,UIActivityTypeAssignToContact,UIActivityTypeSaveToCameraRoll, UIActivityTypeMail, UIActivityTypeMessage];

    //[activityPostVC setExcludedActivityTypes:excludedItems];

    [activityPostVC setExcludedActivityTypes:@[UIActivityTypePrint,UIActivityTypeCopyToPasteboard,UIActivityTypeAssignToContact,UIActivityTypeSaveToCameraRoll, UIActivityTypeMail, UIActivityTypeMessage]];

    [self presentViewController:activityPostVC animated:YES completion:nil];

}

If I run the code either with the excludedItems array declared or implied I still get the memory leak. If I do not include either way of excluding items, I don't get a memory leak. So I think I've isolated it to this array.

Is there something I am doing wrong? Could this be a bug in Apple's code?

4

1 回答 1

1

几乎可以肯定你的 UIActivityViewController 没有被重新分配,但它总是有可能(尽管)Apple 不太可能在这里发生泄漏。

两个想法:

1)子类 UIActivityViewController 在你使用它的文件中,创建一个简单的子类,它只是在 dealloc 例程中记录一些东西。确保实际上这是首先被释放的。

2)如果是,则在dealloc中将excludedItems属性设置为nil,并查看泄漏是否发生变化。

@interface MyUIActivityViewController : UIActivityViewController
@end

@implementation MyUIActivityViewController
- (void)dealloc
{
    NSLog(@"@ MyUIActivityViewController dealloc");

    //self.excludedActivityTypes = nil;
}
@end
于 2013-06-05T17:58:13.893 回答