• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSImages are killing my WindowServer
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

References: 
 >Re: NSImages are killing my WindowServer (From: Troy Stephens <email@hidden>)

  • Prev by Date: Re: menu extras
  • Next by Date: Re: Does anyone know what iCal events are?
  • Previous by thread: Re: NSImages are killing my WindowServer
  • Next by thread: Edit NSPopUpButtonCell like a text cell
  • Index(es):
    • Date
    • Thread