2009-06-01 62 views
1

這段代碼從我正在處理的項目中分離出來。它始終在我的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. 

任何幫助是非常讚賞, 感謝, 克里斯托夫

+0

您還沒有說過;您是否在auto_refcount_underflow_error上設置了斷點以查看發生何時何地? – Abizern 2009-06-01 22:35:20

回答

2

這有被蘋果公司的人確認爲OX X 10.5.7中的一個bug。

rdar:// problem/6938657