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?

Undo
  • 25,519
  • 37
  • 106
  • 129
MplsRich
  • 137
  • 1
  • 13

1 Answers1

1

Almost for sure your UIActivityViewController is not getting realloced, but its always possible (though) unlikely that Apple has a leak here.

Two ideas:

1) subclas UIActivityViewController in the file you use it, create a trivial subclass that simply logs something in a dealloc routine. Make sure that in fact this is getting dealloc'd first.

2) if so, the set the excludedItems property to nil in the dealloc, and see if the leak changes.

@interface MyUIActivityViewController : UIActivityViewController
@end

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

    //self.excludedActivityTypes = nil;
}
@end
David H
  • 40,852
  • 12
  • 92
  • 138
  • David - thanks for this. The solution you provided did work as you mentioned. – MplsRich Jun 05 '13 at 18:22
  • @gatorNation But was the problem the object getting deallocated, or that Apple really does have a bug? – David H Jun 05 '13 at 18:32
  • When I implemented the subclass of UIActivityViewController with the dealloc code but WITHOUT setting the excludedActivityTypes to nil, I did get the dealloc message in NSLog, but I still had the leak. So I had to implement the self.excludedActivityTypes = nil. Can you deduce from my observation, cause I'm having trouble seeing the big picture still :( – MplsRich Jun 05 '13 at 19:16