我刚刚在我的应用中发现内存泄漏,但我不确定如何修复它。它涉及一个活动视图,用于共享从rss Feed查看的当前文章的URL。我不确定泄漏发生的原因。任何想法或建议?
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];
}
}
答案 0 :(得分: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上的popover漏洞。
答案 1 :(得分: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];
}
希望它能解决您的问题。