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 16:13:51 -0700
Troy Stephens wrote on Thursday, March 23, 2006:
>On Mar 23, 2006, at 12:01 PM, James Bucanek wrote:
>> Thanks Troy, but the situation a tad more complicated. I already
>> have temporary autorelease pools set up, but these are in separate
>> worker threads. The producer threads create the objects, which are
>> then passed to consumer threads via a queue where they get
>> processed and released. Each producer thread maintains a temporary
>> autorelease pool that it releases from time-to-time. But just to
>> make things more interesting, the producer code is recursive. So
>> the producer thread could have 20 or more nested autorelease pools,
>> each with scores of objects that have accumulated. So the peek
>> number of autoreleased object can be rather high, and there's no
>> simple code alteration that is going to change that.
>
>In that case, you are probably better off keeping the generated
>images out of your autorelease pools altogether (if you can), and
>handing them off to your receiver thread with a clear "caller takes
>ownership and is responsible for releasing" semantic.
I agree (and I've done with with other "heavy" object) -- but right now that sounds a lot like work. :)
Seriously, I found what is probably a better solution. I created a small cache of NSImages and created a factory that recycles them. I hacked the code I could compare would happen if I released the NSImage objects immediately in the consumer thread vs. reusing them, and reusing them is much better.
>> For my really heavy-weight objects I've taken to creating pairs of
>> methods: One that returns an autoreleased object and one that
>> returns a retained object. This lets me immediately release objects
>> with large footprints. But I don't have this luxury (can doing your
>> own memory management be considered a luxury?) with many of the
>> Cocoa objects.
>
>Which other kinds of Cocoa objects (besides NSImages) are piling up
>and causing problems?
None. I mean, none of the other objects (NSStrings, NSEnumerators, NSDictionaries, NSData, ...) that I leave hanging around in the autorelease pools are any problem at all. The problem was that (it seems) that every NSImage object I was creating was causing some matching window/buffer/resource/whatever to be created in the WindowServer daemon. A hundred NSEumerators in the pool is no big deal. A hundred windows, on the other hand...
--
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