Re: Odd crash only when Toast running
Re: Odd crash only when Toast running
- Subject: Re: Odd crash only when Toast running
- From: Shawn Erickson <email@hidden>
- Date: Tue, 2 Jun 2009 07:57:18 -0700
On Tue, Jun 2, 2009 at 12:12 AM, Graham Cox <email@hidden> wrote:
>
> On 02/06/2009, at 4:23 PM, Trygve Inda wrote:
>> The only thing I can find that may be related (based on [NSWindow
>> displayIfNeeded] being in the report) is that my app has a single window
>> with a single view and I call:
>>
>> NSImage* theImage = [[[NSImage alloc]
>> initWithContentsOfFile:mapImagePath] autorelease];
>>
>> [window orderFront:self];
>
> You could try doing this step first, before alloc/init the image. I'm
> wondering if this is causing a drain of the autorelease pool.
It can't cause the autorelease pool related to the current method to
be draining.
>> [imageView setImage:theImage];
>> [imageView setNeedsDisplay:YES];
>>
>> The file that this image comes from will be deleted later on, but once
>> initWithContentsOfFile is called, I assume it no longer needs the file,
>> right?
No it might still need the file. NSImage is often lazy about what it
does so as to not waste resources until they are needed. Can you
outline what you are doing with the file after you create the NSImage
instance? Are you writing to it again, etc.?
As a test I would try sending an -isValid message to the image
instance (think isValid is the correct name) after creating it.
>> I assume the autorelease is ok since theImage will be retained by
>> imageView.
>
> Yes, unless it was autoreleased before that step was invoked, in which case
> <theImage> will be stale which could be crashing the RIP internals.
His code example shows no management of an autorelease pool here so...
> Why not just -release the image after calling setImage, rather than
> autoreleasing?
It is a fairly common Cocoa programming pattern to do the allocation,
init, and memory management all in a single line. Helps avoid a
missing a later release because omission or logic flow error.
-Shawn
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden