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.

Bug 204804 - Memory leak in ToggleBookmarkAction
Summary: Memory leak in ToggleBookmarkAction
Status: VERIFIED FIXED
Alias: None
Product: editor
Classification: Unclassified
Component: Actions/Menu/Toolbar (show other bugs)
Version: 7.1
Hardware: PC Linux
: P3 normal (vote)
Assignee: Miloslav Metelka
URL:
Keywords: PERFORMANCE
Depends on:
Blocks:
 
Reported: 2011-11-07 21:13 UTC by Jesse Glick
Modified: 2012-02-29 12:21 UTC (History)
2 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Reference chain (40.29 KB, image/png)
2011-11-07 21:13 UTC, Jesse Glick
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jesse Glick 2011-11-07 21:13:21 UTC
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.
Comment 1 Miloslav Metelka 2012-02-01 08:54:38 UTC
Thanks, Jesse.

http://hg.netbeans.org/jet-main/rev/036efadb4e0c
Comment 2 Jiri Prox 2012-02-01 12:35:45 UTC
verified in trunk
Comment 3 Jesse Glick 2012-02-01 15:53:35 UTC
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.)
Comment 4 Jesse Glick 2012-02-01 15:56:51 UTC
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.
Comment 5 Miloslav Metelka 2012-02-02 11:23:08 UTC
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.
Comment 6 Quality Engineering 2012-02-09 02:39:06 UTC
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.
Comment 7 Jesse Glick 2012-02-14 18:32:33 UTC
(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.
Comment 8 Jiri Prox 2012-02-29 12:21:40 UTC
v.