Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8353902

[macOS] NSScreens leaked when any window minimized or put into fullscreen

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P3 P3
    • tbd
    • jfx24
    • javafx
    • None
    • macOS 14 and above

      Starting with macOS 14 whenever a window is minimized or restored the OS is discarding all existing NSScreen objects and building new ones. It’s also sending out a notification that the screen configuration has changed (NSApplicationDidChangeScreenParametersNotification). At least this is happening with the default settings; if you turn on “Minimize windows into application icon” in System Preferences it will stop.

      This same behavior occurs when entering or exiting fullscreen. According to JDK-8096309 this has been happening since macOS 10.10.

      Note that this rebuilding behavior occurs whenever *any* window changes minimization or fullscreen state, even windows in other applications.

      Whenever this happens JavaFX leaks all of the old NSScreen objects. Each one is attached to a JavaFX Screen and since glass can’t determine the lifetime of a Screen it retains the NSScreen object forever.

      I think the leaks can be fixed. Instead of attaching the NSScreen pointer to the JavaFX Screen we can attach a CGDirectDisplayID. This is a 32-bit number that according to Apple "typically remains constant until the machine is restarted". When the Java side passes this ID back to glass we can look up the related NSScreen on-the-fly.

      The attached test case monitors the list of Screens and optionally the screen property of the stage. See the comment for how to build this so it can monitor the private Window.screen property.

            arapte Ambarish Rapte
            mfox Martin Fox
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: