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

KeybardFocusManager - static newFocusOwner keeps holding reference

XMLWordPrintable

    • generic
    • generic

      ADDITIONAL SYSTEM INFORMATION :
      Windows 10, Java 17, 21


      A DESCRIPTION OF THE PROBLEM :
      The field newFocusOwner (private static Component) in KeyboardFocusManager does not get cleared and there is no way to clear it programmatically.

      Depending on the referenced component, this keeps a whole tree of components and other related objects in memory.

      This is not only a memory-consumption issue, but also a problem trying to keep the application in 'clean' state.


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Sorry - can't reliably describe a way to reproduce.
      Often this happens when having a Ok/Cancel-JOptionPane and there selecting the Cancel-option.


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      newFocuOwner to be cleared 'reliably'
      ACTUAL -
      newFocusOwner keeps a reference to an otherwise unreferenced component

      ---------- BEGIN SOURCE ----------
      Sorry, up to now I could not find a simple example to reproduce it.
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      None from normal user point of view.

      Maybe instead of having a direct static reference

        private static Component newFocusOwner

      it can be solved by using a WeakReference:

        private static WeakReference<Component> newFocusOwner

      in KeyboardFocusManager.


      FREQUENCY : often


            pnarayanaswa Praveen Narayanaswamy
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: