UIActivityViewController - can't understand th

2019-09-19 06:23发布

问题:

Can someone please tell me why the following code is leaking in Instruments?

UIActivityViewController *activityController = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
activityController.excludedActivityTypes = [NSArray arrayWithObjects:@"a",@"b", nil];


[self presentViewController:activityController animated:YES completion:nil];
[activityController release];    

Instruments show the leak on row:

activityController.excludedActivityTypes = [NSArray arrayWithObjects:@"a",@"b", nil];

回答1:

The following should do the trick (__block and completion)

__block UIActivityViewController *activityController = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
activityController.excludedActivityTypes = [NSArray arrayWithObjects:@"a",@"b", nil];

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

See also this SO