这段代码是从我正在进行的一个项目中分离出来的。它在我的Mac OS 10.5.7上持续再现垃圾收集错误,有时还会崩溃。我已经研究它太久了,所以我的问题是:其他人看到为什么在垃圾收集时会出现错误了吗?
- (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];
}
}
当垃圾回收器释放其中一个映像时,会触发垃圾回收错误消息,如下所示:
reference count underflow for <address>, break on auto_refcount_underflow_error to debug.
谢谢,