• 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
NSImages are killing my WindowServer
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSImages are killing my WindowServer


  • Subject: NSImages are killing my WindowServer
  • From: James Bucanek <email@hidden>
  • Date: Thu, 23 Mar 2006 09:30:40 -0700

Greetings,

I'm hoping that someone with some knowledge of how NSImage works can help me. (Since I rarely -- read "never" -- mess with NSImage, that should be just about everyone...)

I'm working on an application that writes Finder icons to a file -- thousands of them. I wrote to this list some time ago and asked for advice on how to convert an IconRef into an NSImage. (I use the NSImage to encode the icon using TIFF for storage). From these suggestions, I wrote the following little utility:

NSImage* makeNSImageFromIconRef(IconRef iconRef)
{
    CGRect  folderIconSize = { { 0,0 }, { 16,16 } };

    NSImage* image = [[[NSImage alloc] initWithSize:NSMakeSize(16,16)] autorelease];
    [image lockFocus];
    PlotIconRefInContext((CGContextRef)[[NSGraphicsContext currentContext] graphicsPort],
                         &folderIconSize,
                         kAlignNone,
                         kTransformNone,
                         NULL/*inLabelColor*/,
                         kPlotIconRefNormalFlags,
                         iconRef);
    [image unlockFocus];

    return (image);
}

The problem is that after my application runs for a bit, the WindowServer daemon begins to consume the machine. The entire user interface chokes up -- windows, dock, menu, everything is sluggish and stalls for seconds at a time. The virtual memory footprint of WindowServer spikes up to 1.5GB or more, and its CPU usage exceeds 100% (this is on a dual processor system). Also the number of ports reported in top spike up to over a thousand (at which time top simply reports it as '>>>').

As soon as the application stops, WindowServer goes catatonic for about 30 seconds to a minute; chewing up all available CPU time, while its memory usage slowly creeps back down to normal. Eventually it recovers and all it well again.

If I comment the drawing portion of this code out, the application runs normally and WindowServer doesn't get bogged down.

So can anyone make any suggestions on how to address this performance problem? Would it help to release the NSImage immediately instead of letting hundreds of them accumulate in the autorelease pool? Is there some caching or something that I can turn off to keep WindowServer from chewing up so many resources? Should I be reusing a singleton NSImage instead?

--
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

  • Follow-Ups:
    • Re: NSImages are killing my WindowServer
      • From: Ricky Sharp <email@hidden>
    • Re: NSImages are killing my WindowServer
      • From: John Stiles <email@hidden>
  • Prev by Date: Re: value transformer for structs?
  • Next by Date: Re: NSImageView in IB
  • Previous by thread: -objectIn<key>AtIndex not called?
  • Next by thread: Re: NSImages are killing my WindowServer
  • Index(es):
    • Date
    • Thread