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 212261 - Memory leak in BookmarkManager.project2Bookmarks
Summary: Memory leak in BookmarkManager.project2Bookmarks
Status: RESOLVED FIXED
Alias: None
Product: editor
Classification: Unclassified
Component: Navigation (show other bugs)
Version: 7.2
Hardware: PC Linux
: P3 normal (vote)
Assignee: Miloslav Metelka
URL:
Keywords: PERFORMANCE
: 213076 (view as bug list)
Depends on:
Blocks:
 
Reported: 2012-05-09 20:16 UTC by Jesse Glick
Modified: 2012-05-29 17:17 UTC (History)
1 user (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jesse Glick 2012-05-09 20:16:30 UTC
From an IDE session (dev build) in which various projects and files were opened and later all closed, I took a (live) heap dump and found seven leaked NBM projects. Five of them were held by:

this	org.netbeans.modules.apisupport.project.NbModuleProject	#1
key	java.util.HashMap$Entry	#197141
[9]	java.util.HashMap$Entry[]	#3864 (16 items)
table	java.util.HashMap	#3828
project2Bookmarks	org.netbeans.modules.editor.bookmarks.BookmarkManager	#1
INSTANCE	org.netbeans.modules.editor.bookmarks.BookmarkManager	class BookmarkManager

Clearly the project2Bookmarks cache is leaking its keys. (Switching to a WeakHashMap would not help since the values strongly refer to the keys.)
Comment 1 Miloslav Metelka 2012-05-17 13:28:49 UTC
The map is managed by BookmarksPersistence which listens on OpenProjects and removes the notified projects from the map accordingly. Unfortunately I'm unable to reproduce the problem. When debugging regular opening/closing of projects everything gets released appropriately. I've got several ideas that proved not to be the cause so now the only chance I see is that a project being closed gets removed from the map but somehow a bookmark for it gets requested so the infrastructure re-reads its bookmarks and adds it to the map. Jesse, do you have any idea of what could be wrong? Thanks. So I'll check the bookmarks being added against BookmarksPersistence.lastOpenProjects (or OpenProjects) to be sure that the project is still valid.
Comment 2 Jesse Glick 2012-05-18 02:00:23 UTC
(In reply to comment #1)
> a project being
> closed gets removed from the map but somehow a bookmark for it gets requested

This would not be anything out of the ordinary; you open a project, close it, and later use e.g. File > Recent File (or Go to Declaration, etc.) to reopen one of the files from it without opening the whole project.

Safer would be to not hold onto the Project at all (from key or value), and just keep a map keyed by Project.getProjectDirectory().toURI() or the like.
Comment 3 Miloslav Metelka 2012-05-21 14:32:13 UTC
http://hg.netbeans.org/jet-main/rev/6a1015c34aa9
Comment 4 Jesse Glick 2012-05-21 17:20:56 UTC
Beware that

  Project prj = FileOwnerQuery.getOwner(prjURI);

may not be what you want in all cases. For example, if the project at that location has been deleted but was nested inside a larger project, this call will result in

  !BookmarkUtils.toURI(prj).equals(prjURI)

which could cause anomalous behavior. Probably you wanted to use ProjectManager.findProject instead.
Comment 5 Quality Engineering 2012-05-22 16:08:00 UTC
Integrated into 'main-golden', will be available in build *201205220903* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main-golden/rev/6a1015c34aa9
User: Miloslav Metelka <mmetelka@netbeans.org>
Log: #212261 - Memory leak in BookmarkManager.project2Bookmarks.
Comment 6 Miloslav Metelka 2012-05-23 16:04:26 UTC
Jesse, thanks for recommendations.
http://hg.netbeans.org/jet-main/rev/23571d231149
Comment 7 Jesse Glick 2012-05-24 02:48:06 UTC
URLMapper.findFileObject must be checked for a null return value. Quite common - the file does not exist, for example. To be safe you should also check that it is actually a folder.
Comment 8 Quality Engineering 2012-05-25 05:43:47 UTC
Integrated into 'main-golden', will be available in build *201205250002* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)
Changeset: http://hg.netbeans.org/main-golden/rev/23571d231149
User: Miloslav Metelka <mmetelka@netbeans.org>
Log: #212261 - Memory leak in BookmarkManager.project2Bookmarks - using ProjectManager.findProject().
Comment 9 Miloslav Metelka 2012-05-25 11:18:26 UTC
You're right the project could be removed between reading the marks before storing them back.
http://hg.netbeans.org/jet-main/rev/7ea3fab0c1eb
Improved handling of possibly removed sources:
http://hg.netbeans.org/jet-main/rev/f905b9433d3d
Comment 10 Miloslav Metelka 2012-05-29 17:17:47 UTC
*** Bug 213076 has been marked as a duplicate of this bug. ***