This piece of code was split off from a project I am working on. It consistently reproduces a garbage collection error on my Mac OS 10.5.7 and sometimes crashes. I have been looking at it for too long so my question is: does anybody else see why this would give errors when garbage collection is on?
- (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]; } } When playing around with the URLs in the lURLArray I get different behavior: sometimes crashes, sometimes the error message. The garbage collection error message is triggered when the garbage collector is freeing one of the images and goes like this: reference count underflow for <address>, break on auto_refcount_underflow_error to debug. Stack Trace: #0 auto_refcount_underflow_error () #1 Auto::Zone::dec_refcount_small_medium () #2 Auto::Zone::block_decrement_refcount () #3 CFRelease () #4 -[NSBitmapImageRep _freeData] () #5 -[NSBitmapImageRep _freeImage] () #6 -[NSBitmapImageRep finalize] () #7 finalizeOneObject () #8 foreach_block_do () #9 batchFinalize () #10 batchFinalizeOnMainThread () #11 objc_collect_if_needed () #12 NSPopAutoreleasePool () Any help is much appreciated, thanks, Kristof [ see also http://stackoverflow.com/questions/937105/garbage-collection-crash-using-nsimagefor the same question ] Best Regards, Kristof _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com