Re: Does [NSApp setApplicationIconImage] leak memory?
Re: Does [NSApp setApplicationIconImage] leak memory?
- Subject: Re: Does [NSApp setApplicationIconImage] leak memory?
- From: "Michael Ash" <email@hidden>
- Date: Sat, 9 Aug 2008 09:47:39 -0400
On Fri, Aug 8, 2008 at 6:48 PM, Mark Allan <email@hidden> wrote:
>> On Thu, 7 Aug 2008 20:14:04 +0100, Mark Allan
>> <email@hidden>
>> said:
>>>
>>> Hi all,
>>>
>>> Before I file a bug report against this, I just thought I'd check I'm
>>> not being monumentally stupid first!
>>>
>>> I'm trying to animate my app's Dock icon, which works fine and looks
>>> great, but unfortunately, it appears to leak memory like crazy.
>>> Every time I call [NSApp setApplicationIconImage:(NSImage *)] and
>>> pass it pointer to an existing image, it leaks more memory.
>>
>> Wrap each call to setApplicationIconImage in an autorelease pool creation
>> and release, like this:
>>
>> NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
>> [NSApp setApplicationIconImage: whatever];
>> [pool release];
>>
>> I think you'll find that solves the problem.
>
> Sorry, I should have said in my original message that I'd already tried
> that, and the autorelease pool did solve the problem. It's just that doing
> this hundreds (possibly thousands) of times until my process is finished
> seems horribly inefficient. Do you know if it's actually a leak or if it's
> like that by design?
http://www.mikeash.com/?page=pyblog/autorelease-is-fast.html
In short, the cost of creating and destroying an NSAutoreleasePool is
about the same as the cost of creating and destroying two NSObjects.
It is extremely rare that the cost of a pool is noticeable against the
other stuff that your code is doing.
Mike
_______________________________________________
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