You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@netbeans.apache.org by GitBox <gi...@apache.org> on 2018/05/09 19:33:30 UTC

[GitHub] matthiasblaesing commented on issue #515: [NETBEANS-406] Fix a potential memory leak involving DocumentUtilities.addPropertyChangeListener.

matthiasblaesing commented on issue #515: [NETBEANS-406] Fix a potential memory leak involving DocumentUtilities.addPropertyChangeListener.
URL: https://github.com/apache/incubator-netbeans/pull/515#issuecomment-387850642
 
 
   I know that I'm late to the game, but I would try to avoid changing public API. At present it is possible to relax access modifier via reflection, but we see a trend to prevent this (aka Project Jigsaw) on the JDK level and at some point netbeans module system might also enforce this.
   
    As an alternative (untested): 
   
   ```diff
   # This patch file was generated by NetBeans IDE
   # It uses platform neutral UTF-8 encoding and \n newlines.
   --- a/editor.lib2/src/org/netbeans/modules/editor/lib2/view/DocumentViewOp.java
   +++ b/editor.lib2/src/org/netbeans/modules/editor/lib2/view/DocumentViewOp.java
   @@ -37,6 +37,7 @@
    import java.awt.geom.Rectangle2D;
    import java.beans.PropertyChangeEvent;
    import java.beans.PropertyChangeListener;
   +import java.beans.PropertyChangeSupport;
    import java.lang.ref.Reference;
    import java.lang.ref.WeakReference;
    import java.util.Arrays;
   @@ -909,9 +910,12 @@
                Document doc = docView.getDocument();
                updateTextLimitLine(doc);
                clearStatusBits(AVAILABLE_WIDTH_VALID);
   -            DocumentUtilities.addPropertyChangeListener(doc, WeakListeners.propertyChange(this, doc));
   +            PropertyChangeSupport pcs = (PropertyChangeSupport) doc.getProperty(PropertyChangeSupport.class);
   +            if(pcs != null) {
   +                pcs.addPropertyChangeListener(WeakListeners.propertyChange(this, pcs));
            }
        }
   +    }
        
        /* private */ void updatePreferencesSettings(boolean nonInitialUpdate) {
            boolean nonPrintableCharactersVisibleOrig = isAnyStatusBit(NON_PRINTABLE_CHARACTERS_VISIBLE);
   ```
   
   The idea: the `DocumentUtilities#addPropertyChangeListener` just unwraps an `PropertyChangeListener` from the containing Document and attaches to that, this is now done explicitly in `DocumentViewOp`.
   
   @eirikbakke what do you think?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists