我正在尝试在MonoTouch中使用UIActivityViewController。您可以在下面看到代码。我的问题是代码泄漏(根据monotouch内存分析器)并且由于每次显示视图控制器时加载的图像而使用大量内存。我试图实施解决方案:
NSArray* excludedActivities Leaks memory even when using ARC and setting it to nil
How to fix memory leak for UIActivityViewController presented in a UIPopoverController
并将活动视图控制器和图像配置在完成处理程序中,但我总是遇到同样的问题。有人有同样的问题并找到解决方案吗?
void OnButtonClicked(object sender, EventArgs e)
{
UIImage image = UIImage.FromFile("imagePath");
NSObject[] activityItems = new NSObject[] {
new NSString("text"),
image
};
UIActivityViewController activityController = new UIActivityViewController(activityItems, null);
activityController.ExcludedActivityTypes = new NSString[] {UIActivityType.Message};
activityController.CompletionHandler = (activityType, completed) =>
{
activityController.ExcludedActivityTypes = null;
activityController.Dispose();
activityController = null;
image.Dispose();
image = null;
};
this.NavigationController.PresentViewController(activityController, true, () => {});
}