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/09/07 15:50:51 UTC

[GitHub] matthiasblaesing closed pull request #515: [NETBEANS-406] Fix a potential memory leak involving DocumentUtilities.addPropertyChangeListener.

matthiasblaesing closed pull request #515: [NETBEANS-406] Fix a potential memory leak involving DocumentUtilities.addPropertyChangeListener.
URL: https://github.com/apache/incubator-netbeans/pull/515
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/editor.lib2/src/org/netbeans/modules/editor/lib2/view/DocumentViewOp.java b/editor.lib2/src/org/netbeans/modules/editor/lib2/view/DocumentViewOp.java
index 9cc825076a..c93094ebd4 100644
--- 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,7 +910,12 @@ public void run() {
             Document doc = docView.getDocument();
             updateTextLimitLine(doc);
             clearStatusBits(AVAILABLE_WIDTH_VALID);
-            DocumentUtilities.addPropertyChangeListener(doc, WeakListeners.propertyChange(this, doc));
+            /* DocumentUtilities.addPropertyChangeListener does not work with weak listeners, so add the listener explicitly
+            to the underlying PropertyChangeSupport instead. */
+            PropertyChangeSupport pcs = (PropertyChangeSupport) doc.getProperty(PropertyChangeSupport.class);
+            if(pcs != null) {
+                pcs.addPropertyChangeListener(WeakListeners.propertyChange(this, pcs));
+            }
         }
     }
     
diff --git a/editor.util/src/org/netbeans/lib/editor/util/swing/DocumentUtilities.java b/editor.util/src/org/netbeans/lib/editor/util/swing/DocumentUtilities.java
index a070e82de0..bf4180622d 100644
--- a/editor.util/src/org/netbeans/lib/editor/util/swing/DocumentUtilities.java
+++ b/editor.util/src/org/netbeans/lib/editor/util/swing/DocumentUtilities.java
@@ -966,6 +966,8 @@ public static long getDocumentTimestamp(Document doc) {
      * <p>Additionally, the list of document properties that clients can listen on
      * is not part of this contract.
      *
+     * <p>Note that this method does <em>not</em> work with {@code WeakListeners}.
+     *
      * @param doc The document to add the listener to.
      * @param l The listener to add to the document.
      *


 

----------------------------------------------------------------
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