NetBeans 9.0 beta (incubator-netbeans-release-205-on-20180202) on OpenJDK 64-Bit Server VM 188.8.131.52+11, Mac OS 10.9.5
The following warning appears in the IDE log every now and then in 8.2 and 9.0 beta:
The warning above can be reproduced by opening a Java editor, closing all editors, and then invoking a GC with by double-clicking the memory meter in the "Performance" toolbar item.
This bug was previously discussed in Bugzilla at https://netbeans.org/bugzilla/show_bug.cgi?id=196323 . Not sure what priority to put for this bug; it's a memory leak, but I'm not sure how big of an impact it has.
Storing a stacktrace in WeakListenerImpl.ListenerReference on creation and then printing it on the failed removal shows the place where the problematic listener is added:
The problem is on this line of DocumentViewOp:
The DocumentUtilities.addPropertyChangeListener is a special API for allowing property change listeners to be attached to BaseDocument instances (see Bugzilla https://netbeans.org/bugzilla/show_bug.cgi?id=181073 ). Since it doesn't actually add addPropertyChangeListener/removePropertyChangeListener methods to BaseDocument, it doesn't work with WeakListeners.
As far as I can see, the only place that actually uses DocumentUtilities.addPropertyChangeListener is the single line i DocumentViewOp above.
I would propose adding a removedPropertyChangeListener method to BaseDocument that delegates to DocumentUtilities.removePropertyChangeListener (or performs the equivalent logic itself). This way the WeakListener will find the method it expects when the listener is due to be removed, and the property change events will still have the Document instance as the event source instead of the delegate PropertyChangeSupport, as is probably desired.
An alternative is to make WeakListeners aware of the special setup wrt. property change listeners on BaseDocument instances. But that seems like an abstraction violation.