Objective c 使用NSImage的垃圾收集崩溃
这段代码是从我正在从事的一个项目中分离出来的。它总是在我的Mac OS 10.5.7上重复垃圾收集错误,有时还会崩溃。我已经研究它太久了,所以我的问题是:有没有其他人看到当垃圾收集打开时,为什么会出现错误Objective c 使用NSImage的垃圾收集崩溃,objective-c,cocoa,garbage-collection,Objective C,Cocoa,Garbage Collection,这段代码是从我正在从事的一个项目中分离出来的。它总是在我的Mac OS 10.5.7上重复垃圾收集错误,有时还会崩溃。我已经研究它太久了,所以我的问题是:有没有其他人看到当垃圾收集打开时,为什么会出现错误 - (void) doCrash: (id) sender { NSArray *lURLArray = [ NSArray arrayWithObjects: @"http://userserve-ak.last.fm/serve/
- (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];
}
}
在Lurraray中处理URL时,我会得到不同的行为:有时崩溃,有时错误消息
垃圾回收器释放其中一个映像时会触发垃圾回收错误消息,如下所示:
reference count underflow for <address>, break on auto_refcount_underflow_error to debug.
reference count underflow for,自动中断\u refcount\u underflow\u错误以进行调试。
非常感谢您的帮助,
谢谢
克里斯托夫(Kristof)苹果公司的某个人向我证实,这是OX X 10.5.7中的一个bug
rdar://problem/6938657你还没说;您是否在auto_refcount_underflow_error上设置了断点以查看何时/何地发生这种情况?我确实说过:“当垃圾收集器释放其中一个映像时”。堆栈跟踪:#0 auto#refcount#u underflow#u error()#1 auto::Zone::dec#refcount#u small#u medium()#2 auto::Zone::block#u decrement#refcount()#3 CFRelease()#4-[NSBitmapImageRep#freeData()#5-[NSBitmapImageRep#freeimagerep image]()#6-[NSBitmapImageRep freeimagerep finalize]()#7-[nsbitmapagerep finalize]#finalize()35#10 BatchFinalizationOnMainThread()#11 objc#U collect(如果需要#()#12 NSPopAutoreleasePool()