NSCFString自动释放没有池 - 只是泄漏?

时间:2011-04-17 21:11:11

标签: xamarin.ios

我突然在我的控制台日志中运行了数百条这样的行,运行了一个使用我实现的进度控制器的进程:

** __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() 但为什么?整个事情已经在一个单独的池中了。

1 个答案:

答案 0 :(得分:7)

此链接可以帮助您http://blog.datispars.com/tasks-in-background-thread-cocoa-performselectorinbackground/ 每个线程都应该拥有自己的自动释放池