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

CSS: StyleManager does not hold strong reference to StyleHelpers

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: fx2.1
    • Fix Version/s: 7u6
    • Component/s: javafx
    • Labels:

      Description

      StyleHelper is a Reference in Node since StyleManager might invalidate the helper (if, for example, scene stylesheets change). But no where is there a strong reference to the StyleHelper, so they keep getting recreated even though there is no need to recreate them.

      The following change is needed, but it is too late to go into 2.1:


      diff -r ca0f557cdc2d javafx-ui-common/src/com/sun/javafx/css/StyleManager.java
      --- a/javafx-ui-common/src/com/sun/javafx/css/StyleManager.java Mon Mar 05 22:27:45 2012 -0500
      +++ b/javafx-ui-common/src/com/sun/javafx/css/StyleManager.java Thu Mar 08 09:46:55 2012 -0500
      @@ -1116,25 +1116,20 @@
               private final List<Rule> rules;
               private final long pseudoclassStateMask;
               private final boolean impactsChildren;
      - private final Map<Long, Reference<StyleHelper>> cache;
      + private final Map<Long, StyleHelper> cache;
       
               Cache(List<Rule> rules, long pseudoclassStateMask, boolean impactsChildren) {
                   this.rules = rules;
                   this.pseudoclassStateMask = pseudoclassStateMask;
                   this.impactsChildren = impactsChildren;
      - cache = new HashMap<Long, Reference<StyleHelper>>();
      + cache = new HashMap<Long, StyleHelper>();
               }
       
               private void clear() {
       
      - for(Reference<StyleHelper> helperRef : cache.values()) {
      - StyleHelper helper = helperRef.get();
      - if (helper == null) {
      - continue;
      - }
      + for(StyleHelper helper : cache.values()) {
                       helper.valueCache = null;
                       helper.clearStyleMap();
      - helperRef.clear();
                   }
       
                   cache.clear();
      @@ -1184,11 +1179,10 @@
                   }
       
                   if (cache.containsKey(key)) {
      - Reference helperRef = cache.get(key);
      - if (helperRef.get() != null) {
      - return helperRef;
      + StyleHelper helper = cache.get(key);
      + if (helper != null) {
      + return new WeakReference<StyleHelper>(helper);
                       }
      - cache.remove(key);
                   }
                   
                   // We need to create a new StyleHelper, add it to the cache,
      @@ -1197,11 +1191,11 @@
                   final StyleHelper helper =
                       StyleHelper.create(styles, pseudoclassStateMask,
                           ++(container.helperCount));
      - final Reference helperRef = new WeakReference(helper);
       
                   helper.valueCache = container.valueCache;
      - cache.put(key, helperRef);
      - return helperRef;
      + cache.put(key, helper);
      +
      + return new WeakReference<StyleHelper>(helper);
               }
       
               /**

        Attachments

          Activity

            People

            • Assignee:
              dgrieve David Grieve (Inactive)
              Reporter:
              dgrieve David Grieve (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported: