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.
Any help is much appreciated, thanks, Kristof