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

Memory leak due to remaining strong references caused by property binding

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 8
    • 7u21
    • javafx
    • None

      Assume you have the following:
      label.textProperty().bind(person.nameProperty());

      Now assume the 'label' above is no longer part of the scene graph, and that it is no longer referenced from application code.

      If 'person' is still around, 'label' is not being garbage-collected, due to a strong reference from the 'name' property of 'person' on the 'text' property of 'label', causing a memory leak.

      This problem doesn't occur with bidirectional bindings, or low-level bindings, as in the below, given that those apparently use weak references:
      label.textProperty().bindBidirectional(person.nameProperty());

      label.textProperty().bind(new StringBinding() {
              
        {
          bind(person.nameProperty());
        }

        @Override
        protected String computeValue() {
          return person.nameProperty().get();
        }
      });

            msladecek Martin Sládeček
            sbozianjfx Shant Bozian (Inactive)
            Votes:
            1 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: