基本情况是我有一个自定义的NSURLProtocol
。在startLoading
中,[self client]
的类型为:
<_NSCFURLProtocolBridge> {NSURLProtocol, CFURLProtocol}
问题在于在垃圾回收环境中运行此代码。因为我正在编写屏幕保护程序,所以必须使用垃圾回收。但是,_NSCFURLProtocolBridge协议似乎总是会引发以下错误:
下面是一个示例调试信息:
malloc: reference count underflow for (memory_id_here), break on auto_refcount_underflow_error to debug
您可以看到,这个错误出现在
ScreenSaverEngine[1678:6807] client is <_NSCFURLProtocolBridge 0x20025ab00> {NSURLProtocol 0x200258ec0, CFURLProtocol 0x20029c400}
ScreenSaverEngine(1678,0x102eda000) malloc: reference count underflow for 0x20025ab00, break on auto_refcount_underflow_error to debug.
<_NSCFURLProtocolBridge 0x20025ab00>
处。当我在
auto_refcount_underflow_error
上打断点时,它似乎会在 URLProtocolDidFinishLoading:
中返回堆栈跟踪:id client = [self client];
...
[client URLProtocolDidFinishLoading:self];
这个问题似乎已经存在一段时间了,但是在网上似乎没有任何答案:
http://lists.apple.com/archives/cocoa-dev/2008/May/msg01272.html http://www.cocoabuilder.com/archive/message/cocoa/2007/12/17/195056
这些列出的bug只在使用垃圾回收环境时才会出现。有什么办法可以解决这个问题而不引起内存问题吗? 我认为这可能与NSURLProtocol下面的CF类型释放不当有关?