Re: NSImage release crash
Re: NSImage release crash
- Subject: Re: NSImage release crash
- From: Paul Collins <email@hidden>
- Date: Tue, 2 Nov 2004 08:54:53 -0800
Followup question:
It's been suggested that my woes may stem from executing code in a callback--the misbehaving NSImages are created in code within a CFNetwork callback. I haven't noticed any documentation stating that there are limitations on what code may be executed in a CFNetwork callback.
Did I miss something? Can I create objects within a callback or not?
Thanks,
Paul Collins
On Nov 1, 2004, at 2:21 PM, Paul Collins wrote:
My app is crashing in [NSImage dealloc]. In testing, I create about 3000 128 x 128 NSImages (resized from various larger images from disk), keep them around for browsing (a la iPhoto contact sheet view), then later release them while closing my document window. While releasing the 3000 images, one of them causes a crash (in testing, it's been like the 1075th image, or 2054th image (in two tests the same image crashed, although the image itself is not a problem when used in a small group of images).
I can replicate the crash in the debugger with NSZombie on, and get no zombie exceptions, so I infer that this is not a double-free/double-release bug. Here's a crash log:
Exception: EXC_BAD_ACCESS (0x0001)
Codes: KERN_PROTECTION_FAILURE (0x0002) at 0x026eb97b
Thread 0 Crashed:
0 com.apple.AppKit 0x92ebb5e4 AddSpace + 0x1a4
1 com.apple.AppKit 0x92e65b6c _NXFreeImageCache + 0x1f0
2 com.apple.AppKit 0x92e2fc10 -[NSCachedImageRep dealloc] + 0x184
3 com.apple.AppKit 0x92e1315c -[NSImage _freeRepresentation:] + 0x144
4 com.apple.AppKit 0x92e278a4 -[NSImage dealloc] + 0x6c
5 ODSlide.ob 0x017e0704 -[ODSlide setThumbImage:] + 0x50 (ODSlide.m:48)
6 ODSlide.ob 0x017e35d4 -[ODSlide dealloc] + 0xc4 (ODSlide.m:823)
Here's the code used to create the image:
NSImage *theImage = nil;
NS_DURING
theImage = [[NSImage alloc] initWithContentsOfFile:[aSlide cachePath]]; // can raise exception
if (theImage) {
[theImage setScalesWhenResized:YES];
[theImage setFlipped:YES];
// calculate proportional size to fit in 128 x 128 pixels and set that size
[theImage setSize:[(MyDocument *)myDoc bestSize:mySize toFit:thumbsize offset:&thumbImgDelta]];
// pre-cache the image by locking focus
[theImage recache];
NS_DURING
[theImage lockFocus];
[theImage unlockFocus];
NS_HANDLER
ODLog(@"Exception: NSImage -lockFocus failed ");
NS_ENDHANDLER
// retain the image in my custom object.
[slide setThumbImage: theImage];
// [aSlide makeThumbnailIfNoneForDoc:owner withImage:theImage size:NSMakeSize(128,128)]; // only returns image if loaded to make thumbnail, ignored
[theImage release];
NS_HANDLER
NSLog(@"Exception loading or using cached image (possibly unreadable graphic format)");
NS_ENDHANDLER
This code is called within a CFNetwork callback (it's just downloaded the original image). Would that be a problem? I could run it from an NSTimer after the callback if that's better.
This bug appears to have been introduced while fixing other bugs - the major other fix was adding several NSAutoreleasePools to ensure timely releases, although these are not involved this this object.
Any suggestions on how to avoid or at least diagnose this bug?
Thanks,
Paul Collins
** Gracion Software http://www.gracion.com/ **
** Tel: +1 (541) 488-3488 iChat/AV/AIM: gracionsoft **
** DigiTunnel 1.3 PPTP/VPN client for OS X **
** Now shipping! Envision: the new way to experience the web **
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
** Gracion Software http://www.gracion.com/ **
** Tel: +1 (541) 488-3488 iChat/AV/AIM: gracionsoft **
** DigiTunnel 1.3 PPTP/VPN client for OS X **
** Now shipping! Envision: the new way to experience the web **
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden