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

Provide infrastructure to make it possible for properties to delay listener registration

    XMLWordPrintable

Details

    • Enhancement
    • Resolution: Unresolved
    • P4
    • tbd
    • None
    • javafx
    • None
    • In Review

    Description

      Properties often have dependencies on other properties. Adding a standard listener on a dependency means that the property cannot be garbage collected until the listener is removed. There are a few strategies for dealing with this:

      1) Use a weak listener

      This ties you to the whims of the garbage collector which may respond later than expected, or earlier than expected (when the property is still in use) when there are no other strong references. The use of weak listeners also leaves behind stubs on the dependency which need cleaning periodically.

      2) Require calling of a "dispose" method (ie. dispose, unbind, removeListener)

      This leaves the clean up of the listener up to the user; the user is however often not in an easy position to call such a method, requiring a lot of manual book keeping when using a property that uses this style of listener management

      3) Let the property track its own usage, and register and unregister listeners as needed.

      In short, lift the functionality in LazyObjectBinding to ObservableValue and make it public API.

      The idea here is that a property which is used itself can safely add listeners on a dependency. As soon as the property becomes unused, it removes listeners on its dependencies. Such properties are much easier to manage (especially when they're intermediate properties) as only the top level property needs to be managed by the user (using ObservableValue#when for example).

      This ticket is a request to implement infrastructure for the 3rd option in this list.

      It would add observed/unobserved methods to all ObservableValue's which can be hooked into to by any property implementation to only have listeners on dependencies registered when observed itself.

      It also promotes the isObserved method to be public on the ObservableValue interface, which is leveraged by code in observed/unobserved handlers.

      Attachments

        Issue Links

          Activity

            People

              jhendrikx John Hendrikx
              jhendrikx John Hendrikx
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated: