NSCFString 在没有池的情况下自动释放 - 只是泄漏? [英] NSCFString autoreleased with no pool in place - just leaking?
问题描述
我突然在控制台日志中看到数百行这样的行,我正在运行一个使用我实现的进度控制器的进程:
I suddenly get hundreds of these lines in my console log running a process which uses a progress controller I implemented:
** __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() 从网络下载文件.我很困惑如何处理这个问题,因为我不知道可能导致问题的原因.运行下载的线程嵌入在
I'm in a multithreaded environment on iPhone Simulator, downloading a file from the web using WebClient(). I am puzzled how to deal with this as I have no idea what might cause the problem. The thread that is running the download is embedded in
using ( var oAutoRelease = new NSAutoreleasePool ( ) )
我附加到 WebClient 的 DownloadProgressChanged
方法,并在其中调用更新进度视图的委托.如果我删除这一行,警告就会消失:
I'm attaching to the WebClient's DownloadProgressChanged
method and in there I call a delegate which updates the progress view. If I remove this line, the warnings are gone:
ProgressInfo(ACTION.ReceivingResponse, e.ProgressPercentage);
轮流调用委托会回到我的进度控制器并更新标签:
Calling the delegate in turns will go back to my progress controller and udpate a label:
// iIndicator = the value of e.ProgressPercentage.
oProgressController.CurrentActivity = "Percentage done: " + iInidicator.ToString ( ) + "%";
// ProgressController.CurrentActivity:
this.InvokeOnMainThread(delegate { this.oLblCurrentActivity.Text = value; });
我在这里错过了什么!?
What am I missing here!?
我发现我必须在 this.InvokeOnMainThread(delegate { this.oLblCurrentActivity.Text = value; }); 周围放置另一个 NSAutoReleasePool();
但为什么?整个事情已经在一个单独的池中.
I figured out that I had to put another NSAutoReleasePool() around this.InvokeOnMainThread(delegate { this.oLblCurrentActivity.Text = value; });
But why? The whole thing is already in a separate pool.
推荐答案
此链接应该可以帮助您 http://blog.datispars.com/tasks-in-background-thread-cocoa-performselectorinbackground/每个线程都应该有自己的自动释放池
This link should help you http://blog.datispars.com/tasks-in-background-thread-cocoa-performselectorinbackground/ Each thread should have it's own autorelease pool
这篇关于NSCFString 在没有池的情况下自动释放 - 只是泄漏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!