【发布时间】:2011-04-17 21:11:11
【问题描述】:
我突然在控制台日志中看到数百行这样的行,运行一个使用我实现的进度控制器的进程:
** __NSAutoreleaseNoPool(): Object 0x7afafd0 of class NSCFString autoreleased with no pool in place - just leaking
** __NSAutoreleaseNoPool(): Object 0xd8ca4a0 of class __NSCFData autoreleased with no pool in place - just leaking
我在 iPhone 模拟器上的多线程环境中,使用 WebClient() 从 Web 下载文件。我很困惑如何处理这个问题,因为我不知道是什么导致了这个问题。运行下载的线程嵌入在
using ( var oAutoRelease = new NSAutoreleasePool ( ) )
我正在附加到 WebClient 的 DownloadProgressChanged 方法,并在其中调用一个委托来更新进度视图。如果我删除这一行,警告就会消失:
ProgressInfo(ACTION.ReceivingResponse, e.ProgressPercentage);
依次调用代理将返回我的进度控制器并更新标签:
// iIndicator = the value of e.ProgressPercentage.
oProgressController.CurrentActivity = "Percentage done: " + iInidicator.ToString ( ) + "%";
// ProgressController.CurrentActivity:
this.InvokeOnMainThread(delegate { this.oLblCurrentActivity.Text = value; });
我在这里错过了什么!?
编辑:我发现我必须在 this.InvokeOnMainThread(delegate { this.oLblCurrentActivity.Text = value; }); 周围放置另一个 NSAutoReleasePool()
但为什么?整个东西已经在一个单独的池中。
【问题讨论】:
-
池中没有东西,可能是异步方法的回调。
标签: xamarin.ios