Re: NSImages are killing my WindowServer
Re: NSImages are killing my WindowServer
- Subject: Re: NSImages are killing my WindowServer
- From: James Bucanek <email@hidden>
- Date: Thu, 23 Mar 2006 13:08:27 -0700
John Stiles wrote on Thursday, March 23, 2006:
>On Mar 23, 2006, at 10:35 AM, James Bucanek wrote:
>> Looking at the structure of my code, I think it might be easier to
>> create a cache. All of the code that calls this function expects an
>> autoreleased NSImage, and I'd have to return a retained one if I
>> want the clients to release it immediately.
>
>The client code couldn't just wrap it with a new NSAutoreleasePool?
Not easily. The problem is that the images are created in various methods of one thread, which then pass them through a queue to a consumer thread that does the encoding and writes them to the file. There is no "big loop" to wrap around the life cycle of the NSImage. My producer and consumer threads already have working autorelease pools which they flush occasionally, but this still can't do anything about the large number of object that might be "in flight" at any one time.
>Maybe something along these lines:
> [[NSColor clearColor] set];
> NSRectFill( ... your image's frame ... );
Brilliant.
This works great. I just replaced the code that was spewing out reams of NSImages with a factory/cache that reuses NSImages whenever possible. The result is that my code typically doesn't need more than 3 or 4 NSImages at a time. It's *much* faster and WindowServer is its normal, mostly idle, self.
Thanks everyone for all of the suggestions and feedback. This has been very educational.
Cheers,
James
--
James Bucanek
_______________________________________________
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