1

I work on a macOS app which uses the CoreGraphics APIs to retrieve the whole screen as an image, or the various windows of an application. This is for a screen sharing feature. We occasionally run into an issue where Apple's WindowServer process starts to consume a lot of CPU (close to 100%) and the whole system becomes incredibly sluggish, almost unusable.

If you kill the WindowServer, or kill our app, then things return to normal. The problem persists even when you stop the screen sharing and we aren't calling the APIs anymore, until you terminate our app.

Has anyone worked with the CoreGraphics APIs, or have knowledge of how that connects with the WindowServer process to give some insight into what we might be doing that perturbs the Windows Server in these cases?

A spindump of the system shows that indeed our app and others are waiting on the WindowServer, which is taking up almost all the time of the spindump in its main thread. Seems like some kind of "soft" deadlock, since the WindowServer isn't completely frozen (since the UI is still somewhat accessible). It's an infrequent, but very troublesome occurrence.

TylerH
  • 20,799
  • 66
  • 75
  • 101
LarryW
  • 89
  • 9
  • Which APIs? `CGDisplayCreateImage`? `CGDisplayStreamCreate`? Are you sure you're timely releasing resources created from each captured frame? – rob mayoff Jul 23 '18 at 20:32
  • @robmayoff We are actually using `CGWindowListCreateImageFromArray` as we only want to capture certain application windows. From what I can tell, we are releasing the captured `CGImage`'s when we are done copying their data to our own format. Sometimes that's right after the capture, and other times it's upon capturing the next frame. That could be optimized, but I don't see that it should be the cause of such a drastic problem. The resources should be quickly cleaned up. – LarryW Jul 27 '18 at 21:26

0 Answers0