This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.
Created attachment 112958 [details] Reference chain Dev build; all files long since closed, but various editor panes held in heap. Root reference chain shows that ToggleBookmarkAction's constructor calls EditorRegistry.addPropertyChangeListener but fails to use a weak listener, so each instance - and thus its editor pane - is held in memory forever.
Thanks, Jesse. http://hg.netbeans.org/jet-main/rev/036efadb4e0c
verified in trunk
WeakListeners would probably be easier. E.g. just make ToggleBookmarkAction implement PropertyChangeListeners, with body simply "updateEnabled();", then EditorRegistry.addPropertyChangeListener(WeakListeners.propertyChange(this, EditorRegistry.class)); (The 2nd arg makes sure EditorRegistry.removePropertyChangeListener is called when the ref is cleared.)
I am not sure if memory leak bugs are good patch candidates: 1. The fixes often introduce new bugs (race conditions, etc.) or do not actually work at all (since it is tricky to reproduce the original bug). 2. A given large object, such as a Project, is incorrectly held in heap if there is _any_ buggy reference chain to it; you have to fix _all_ the contributing bugs for there to be any visible effect. This is best done as part of a dev cycle using thorough functional tests.
I had exactly EditorRegistry.addPropertyChangeListener(WeakListeners.propertyChange(this, EditorRegistry.class)); in the code ;) but then I've asked Tomas Z. who said that it would not work (for static listener methods) so I've changed it. Good to know that it actually works. Thanks. ad 1) In this case opening a source with at least one bookmark led to keeping it in memory (due to the other problem introduced by Hanz) so I considered this a serious problem. ad 2) I could possibly make a variant of java.kit/.../WatchProjects.assertTextDocuments() for basic editor checking. Back in NB3.x I used to check for leaking QuietEditorPane and NbEditorDocument before a release as well as I've checked code effectiveness of attached DocumentListener instances. I should probably restart this for future releases.
Integrated into 'releases', will be available in build *201202082200* or newer. Wait for official and publicly available build. Changeset: http://hg.netbeans.org/releases/rev/e8ab32baa968 User: Miloslav Metelka <mmetelka@netbeans.org> Log: #204804 - Memory leak in ToggleBookmarkAction.
(In reply to comment #5) > I've asked Tomas Z. who said that it would not work > (for static listener methods) so I've changed it. Since 2006 - WeakListenersTest.testStaticRemoveMethod BTW.
v.