使用NSImage的垃圾收集崩溃
问题描述:
这段代码从我正在处理的项目中分离出来。它始终在我的Mac OS 10.5.7上重现垃圾回收错误,并且有时会崩溃。我一直在看它太久了,所以我的问题是:其他人看到为什么这会在垃圾回收时发生错误?使用NSImage的垃圾收集崩溃
- (void) doCrash: (id) sender
{
NSArray *lURLArray = [ NSArray arrayWithObjects:
@"http://userserve-ak.last.fm/serve/300x300/23621007.jpg",
@"http://userserve-ak.last.fm/serve/300x300/26675609.png",
@"http://userserve-ak.last.fm/serve/300x300/26675609.png",
nil ];
NSString *lImageURL = nil;
for (lImageURL in lURLArray)
{
NSImage *lImage = [[NSImage alloc] initWithContentsOfURL: [NSURL URLWithString: lImageURL]];
NSSize targetSize = NSMakeSize(80,80);
NSImage *newImage = [[NSImage alloc] initWithSize:targetSize];
[newImage lockFocus];
NSRect thumbnailRect = NSMakeRect(0,0,80,80);
NSRect sourceRect = NSMakeRect(0,0,[lImage size].width,[lImage size].height);
[lImage drawInRect: thumbnailRect
fromRect: sourceRect
operation: NSCompositeSourceOver
fraction: 1.0];
[newImage unlockFocus];
}
}
当在lURLArray的URL玩弄我得到不同的行为:有时会崩溃,有时错误消息。
当垃圾收集器释放的一个图像,会触发垃圾收集错误消息,是这样的:
reference count underflow for <address>, break on auto_refcount_underflow_error to debug.
任何帮助是非常赞赏, 感谢, 克里斯托夫
答
这有被苹果公司的人确认为OX X 10.5.7中的一个bug。
rdar:// problem/6938657
您还没有说过;您是否在auto_refcount_underflow_error上设置了断点以查看发生何时何地? – Abizern 2009-06-01 22:35:20