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.
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.)
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.
(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.
http://hg.netbeans.org/jet-main/rev/6a1015c34aa9
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.
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.
Jesse, thanks for recommendations. http://hg.netbeans.org/jet-main/rev/23571d231149
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.
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().
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
*** Bug 213076 has been marked as a duplicate of this bug. ***