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.
I'm fixing a memory leak in HTML5 project type (issue 230378) and one of the problems (there is more of them) is that removeNotify is never called on my subclass of org.netbeans.spi.project.ui.support.NodeList (org.netbeans.modules.web.clientproject.ui.ClientSideProjectLogicalView.ClientProjectNodeList) and consequently the cleanup of listeners is never performed and result is a memory leak. The Javadoc for NodeList.removeNotify says: * Called when the node list is no longer needed. Equivalent * to {@link org.openide.nodes.Children#removeNotify}. * Unregister any listeners and perform any general cleanup. which is what I would expect. Partially because of the method name is identical to JComponent.removeNotify. However Childer.removeNotify says in its Javadoc: /** Called when all the children Nodes are freed from memory. * Typical implementations at this time clear all the keys * (in case of {@link Children.Keys}) etc. * * Note that this is usually not the best place for unregistering * listeners, etc., as listeners usually keep the child nodes * in memory, preventing them from being collected, thus preventing * this method to be called in the first place. And that's what is happening in HTML5 project: listener created in NodeList.addNotify prevents NodeList subclass from being garbage collected and therefore removeNotify is never called. Could you please clarify how this is intended to work? Thanks.
Children.removeNotify() javadoc applies, maybe it was rewritten at some stage to be more aligned with reality. It's been an issue with removeNotify() for a long time AFAIK.
http://hg.netbeans.org/core-main/rev/54628ce756bb our api is just a wrapper on top of nodes. their contract applies
Thanks. It's weird though as it makes removeNotify fairly useless. I had a look at several subclasses of NodeList and they all look the same: add listener in addNotify and remove it in removeNotify. Which is broken unless listener is a weak listener. But if listener is a weak one then you do not have to bother removing it in remoteNotify at all.
(In reply to comment #3) > Thanks. > > It's weird though as it makes removeNotify fairly useless. I had a look at > several subclasses of NodeList and they all look the same: add listener in > addNotify and remove it in removeNotify. Which is broken unless listener is a > weak listener. But if listener is a weak one then you do not have to bother > removing it in remoteNotify at all. indeed. The behaviour is fairly unintuitive especially given it was named the same as JComponent.removeNotify(). The additional javadoc was added by pnejedly in 2007 - https://netbeans.org/bugzilla/show_bug.cgi?id=99895
Integrated into 'main-golden', will be available in build *201306112301* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress) Changeset: http://hg.netbeans.org/main-golden/rev/54628ce756bb User: Milos Kleint <mkleint@netbeans.org> Log: #231005 updated javadoc