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 70579 - NewFileWizard leaks TemplateChooserPanelGUI if run with predefined file type
Summary: NewFileWizard leaks TemplateChooserPanelGUI if run with predefined file type
Status: VERIFIED FIXED
Alias: None
Product: projects
Classification: Unclassified
Component: Generic Projects UI (show other bugs)
Version: 5.x
Hardware: All All
: P2 blocker (vote)
Assignee: Jan Lahoda
URL:
Keywords: PERFORMANCE
: 70364 (view as bug list)
Depends on:
Blocks:
 
Reported: 2005-12-19 10:12 UTC by Michal Mocnak
Modified: 2005-12-22 13:43 UTC (History)
4 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Call stack of AsyncInitSupport constructor where AWTEventListener is attached (3.61 KB, text/plain)
2005-12-19 10:13 UTC, Michal Mocnak
Details
Call stack of AsyncInitSupport constructor where AWTEventListener is attached (3.61 KB, text/plain)
2005-12-19 10:17 UTC, Michal Mocnak
Details
Proposed patch. (1.41 KB, patch)
2005-12-20 13:52 UTC, Jan Lahoda
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Michal Mocnak 2005-12-19 10:12:17 UTC
When profiling New Action apisupport wizard, I found out that there is
org.openide.explorer.ExplorerManager and related objects leaking via the
following reference path:

  sun.awt.X11.XToolkitThreadBlockedHandler.tk->
  sun.awt.X11.XToolkit@18e2b22->
  java.awt.Toolkit$ToolkitEventMulticaster@1d9d839->
  java.awt.Toolkit$ToolkitEventMulticaster@1cf633f->
  java.awt.Toolkit$SelectiveAWTEventListener@68b475->
  org.openide.util.AsyncInitSupport@1e356a5->
  org.netbeans.modules.project.ui.TemplateChooserPanelGUI@1636bbf->
  org.netbeans.modules.project.ui.TemplatesPanelGUI@11c7768->
  org.netbeans.modules.project.ui.TemplatesPanelGUI$CategoriesPanel@18d21f->
  org.openide.explorer.ExplorerManager@8b063

Debugging the code in AsyncInitSupport I realized that it attaches the
AWTEventListener in its constructor, but its method eventDispatched() never gets
through the condition

  SwingUtilities.isDescendingFrom(comp4Init, (Component) (event.getSource()))

and thus detach() called in start() is never run. The reason is IMHO that the
TemplatesChooserPanelGUI never gets inside NbDialog instance which is here as
the value of event.getSource().

I am not sure where the fix should be. I want to talk to Jirka about it, but I
believe this issue belongs to org.netbeans.modules.project.ui.


------- Additional comments from anebuzelsky Tue Dec 13 23:01:38 +0000 2005

Changing summary from
  NewFileWizard leaks ExplorerManager if run with predefined file type
to
  NewFileWizard leaks TemplateChooserPanelGUI if run with predefined file type
because
TemplateChooserPanelGUI is the closest object to where the leak is held (the
nondetached AWTEventListener). However, the summary of the issue is not
important, the leak is what matters here. :)
Comment 1 Michal Mocnak 2005-12-19 10:13:38 UTC
Created attachment 27939 [details]
Call stack of AsyncInitSupport constructor where AWTEventListener is attached
Comment 2 Michal Mocnak 2005-12-19 10:17:01 UTC
Created attachment 27940 [details]
Call stack of AsyncInitSupport constructor where AWTEventListener is attached
Comment 3 Michal Mocnak 2005-12-19 10:20:21 UTC
*** Issue 70364 has been marked as a duplicate of this issue. ***
Comment 4 Jan Lahoda 2005-12-19 10:21:54 UTC
Any reason why this is not a duplicate of issue #70364?

*** This issue has been marked as a duplicate of 70364 ***
Comment 5 Jan Lahoda 2005-12-19 10:29:05 UTC
Please next time say you are creating a duplicate for a reason. For the record:
see issue #70364 for explanation.
Comment 6 Jan Lahoda 2005-12-19 11:40:35 UTC
The solution seems to be to move "Utilities.attachInitJob (this, this);" from
the constructor into addNotify.

Not sure if I will be able to write a test for this.
Comment 7 Jan Lahoda 2005-12-19 16:43:14 UTC
Hopefully fixed in the trunk. There are three scenarios:
1. on a project node invoke a context menu, New->File/Folder, finish the wizard.
2. on a project node invoke a context menu, New->some predefined template,
finish the wizard.
3. on a project node invoke a context menu, New->some predefined template, but
go "Back" in the wizard and then finish it.

Tonda, could you please verify the fix? Thanks.

Checking in TemplateChooserPanelGUI.java;
/cvs/projects/projectui/src/org/netbeans/modules/project/ui/TemplateChooserPanelGUI.java,v
 <--  TemplateChooserPanelGUI.java
new revision: 1.34; previous revision: 1.33
done
Comment 8 Antonin Nebuzelsky 2005-12-20 13:22:16 UTC
I verified the fix with the 3 scenarios you mention above (finishing the wizard
with Cancel each time). It looks working fine.
You can proceed with backporting to release50 branch. Thanks!
Comment 9 Jan Lahoda 2005-12-20 13:52:21 UTC
Created attachment 27972 [details]
Proposed patch.
Comment 10 Jan Lahoda 2005-12-20 13:54:31 UTC
Jesse, could you please review the fix?

QA, do you agree with the change?

Thanks.
Comment 11 Marian Mirilovic 2005-12-20 15:06:27 UTC
verified in NB 5.1, New File/folder functionality hasn't been affected and
everything works as it should.
Comment 12 Jesse Glick 2005-12-20 16:07:56 UTC
I don't know enough about this to review the patch.
Comment 13 Jan Lahoda 2005-12-20 16:55:08 UTC
Ok, Jirka or Dafe, could you please try to review the patch? Or should I ask
someone else?

Thanks.
Comment 14 Jiri Rechtacek 2005-12-21 09:47:28 UTC
The fix is reasonable and fixes the problem, I'm confirmed with this fix.
Comment 15 Jan Lahoda 2005-12-21 13:46:09 UTC
Fixed in release50 branch too:
Checking in src/org/netbeans/modules/project/ui/TemplateChooserPanelGUI.java;
/cvs/projects/projectui/src/org/netbeans/modules/project/ui/TemplateChooserPanelGUI.java,v
 <--  TemplateChooserPanelGUI.java
new revision: 1.33.54.1; previous revision: 1.33
done
Comment 16 Antonin Nebuzelsky 2005-12-22 13:43:28 UTC
Verified in 5.0 (build 200512212030).