Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 64855

Summary: QuickMenuAction leaks the context menus
Product: [Eclipse Project] JDT Reporter: Erich Gamma <erich_gamma>
Component: UIAssignee: Dirk Baeumer <dirk_baeumer>
Status: VERIFIED FIXED QA Contact:
Severity: major    
Priority: P3 CC: michaelvanmeekeren
Version: 3.0   
Target Milestone: 3.0 RC2   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Erich Gamma CLA 2004-05-31 18:36:22 EDT
According to bug# 62252 the quick menu action leaks its context menu.

Index: QuickMenuAction.java
===================================================================
RCS 
file: /home/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/actions/Q
uickMenuAction.java,v
retrieving revision 1.3
diff -u -r1.3 QuickMenuAction.java
--- QuickMenuAction.java	24 May 2004 14:11:58 -0000	1.3
+++ QuickMenuAction.java	31 May 2004 22:34:31 -0000
@@ -43,6 +43,7 @@
 public abstract class QuickMenuAction extends Action { 
 
 	private static final int CHAR_INDENT= 3;
+	private Menu fQuickMenu;
 	
 	/**
 	 * Creates a new quick menu action with the given command id.
@@ -67,14 +68,26 @@
 		
 		MenuManager menu= new MenuManager();
 		fillMenu(menu);
-		final Menu widget= menu.createContextMenu(focus.getShell());
-		Point location= computeMenuLocation(focus, widget);
+		if (fQuickMenu != null) {
+			fQuickMenu.dispose();
+			fQuickMenu = null;
+		}
+
+		fQuickMenu= menu.createContextMenu(focus.getShell());
+		Point location= computeMenuLocation(focus, fQuickMenu);
 		if (location == null)
 			return;
-		widget.setLocation(location);
-		widget.setVisible(true);
+		fQuickMenu.setLocation(location);
+		fQuickMenu.setVisible(true);
 	}
 	
+	public void dispose() {
+		if (fQuickMenu != null) {
+			fQuickMenu.dispose();
+			fQuickMenu = null;
+		}	
+	}
+
 	/**
 	 * Hook to fill a menu manager with the items of the sub menu.
 	 *
Comment 1 Dirk Baeumer CLA 2004-06-01 04:14:32 EDT
Must fix for RC2.
Comment 2 Dirk Baeumer CLA 2004-06-06 10:17:59 EDT
I fixed this by running an event loop after the menu gets visible. This avoids 
the problem that the menu is still referenced until it gets opened the next 
time. The code I added is as follows:

		while (!widget.isDisposed() && widget.isVisible()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
		if (!widget.isDisposed()) {
			widget.dispose();
		}

Michael, you might want to consider using this fix in your implementaiton of 
QuickMenuAction.
Comment 3 Dirk Baeumer CLA 2004-06-06 10:18:29 EDT
Fixed for > I20040607
Comment 4 Dani Megert CLA 2004-06-11 06:15:46 EDT
start verifying
Comment 5 Dani Megert CLA 2004-06-11 06:23:22 EDT
start verifying
Comment 6 Dani Megert CLA 2004-06-11 06:50:51 EDT
verified in I200406110010 through code inspection