After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 352628 - Memory leak due to the addition of menu accelerators
Memory leak due to the addition of menu accelerators
Status: RESOLVED FIXED
Product: bonobo
Classification: Deprecated
Component: libbonoboui
CVS HEAD
Other All
: Normal normal
: ---
Assigned To: Michael Meeks
bonobo qa
Depends on:
Blocks:
 
 
Reported: 2006-08-24 01:03 UTC by Cecilia Gonzalez
Modified: 2006-08-29 01:17 UTC
See Also:
GNOME target: ---
GNOME version: 2.15/2.16


Attachments
Avoid the useless adding of menu accelerators. (1.48 KB, patch)
2006-08-24 01:10 UTC, Cecilia Gonzalez
none Details | Review
Changelog of the submitted patch (304 bytes, text/plain)
2006-08-24 01:13 UTC, Cecilia Gonzalez
  Details

Description Cecilia Gonzalez 2006-08-24 01:03:01 UTC
Please describe the problem:
The problem has been detected in Evolution. Every switch between components causes an increase of the time of switching. This behaviour can be observed here: http://m3gumi.wordpress.com/files/2006/07/mixed-real.png
This is caused by the addition of accelerators in menu item many times when once was enough (bonobo-ui-sync-menu.c:impl_bonobo_ui_sync_menu_state()). Moreover, some of these accelerators are never removed, causing memory leak problems which lead to time increasing in the function that add the accelerators.

Steps to reproduce:
1. Automate the switching of Evolution.
2. Get samples of time of every switch in gtk_widget_add_accelerator of function impl_bonobo_ui_sync_menu_state(). Or better, in g_memmove() of quick_accel_add()  (gtkaccelgroup.c).
3. Watch the increase of memory with command top.


Actual results:
Every switch, time for adding accelerators and resident memory of evolution increase.

Expected results:
Time should be constant in every switch. Memory should not grow so much.

Does this happen every time?
Yes.

Other information:
Comment 1 Cecilia Gonzalez 2006-08-24 01:10:52 UTC
Created attachment 71499 [details] [review]
Avoid the useless adding of menu accelerators. 

The patch respects the fact that we can have a widget with multiple accelerators and that the same accelerator can be added many times in the same accelerator group. The code only avoid the accelerator addition if it has been added previously to the same widget (which is the common case observed).
Comment 2 Cecilia Gonzalez 2006-08-24 01:13:20 UTC
Created attachment 71500 [details]
Changelog of the submitted patch
Comment 3 Nickolay V. Shmyrev 2006-08-24 08:21:56 UTC
That's great result and patch, but shouldn't the fix go into gtk?
Comment 4 Michael Meeks 2006-08-24 09:15:17 UTC
I suppose it is slightly odd that gtk+ will allow this multiple identical binding thing to happen, but the patch is fine and at least we prolly shouldn't abuse gtk+ in this way :-)

Please do commit [ is there a similar problem for toolbar icons ? ]
Comment 5 Federico Mena Quintero 2006-08-24 15:19:03 UTC
Cecilia, do you have an account on cvs.gnome.org?  I can commit it for you if you don't, and we can start the process of getting you an account.
Comment 6 Cecilia Gonzalez 2006-08-24 15:50:41 UTC
Hi Federico, I don't have a cvs account.
Comment 7 Gustavo Carneiro 2006-08-24 17:08:57 UTC
Notice that hard code freeze is next monday; someone should commit this soon..
Comment 8 Kjartan Maraas 2006-08-25 09:54:30 UTC
Commited. I'll do another release to get this out the door as soon as possible.
Comment 9 Federico Mena Quintero 2006-08-25 15:19:43 UTC
Thanks for committing this, Kjartan :)

And again, thanks to Cecilia for the wonderful analysis and patch!
Comment 10 Cecilia Gonzalez 2006-08-28 12:55:40 UTC
Comment on attachment 71499 [details] [review]
Avoid the useless adding of menu accelerators. 

--- cvs/libbonoboui/bonobo/bonobo-ui-sync-menu.c_old	2006-08-22 11:33:16.000000000 +0100
+++ cvs/libbonoboui/bonobo/bonobo-ui-sync-menu.c	2006-08-28 13:41:10.000000000 +0100
@@ -282,6 +282,33 @@ label_same (GtkBin *menu_widget, const c
 		!strcmp (((GtkLabel *)label)->label, txt);
 }
 
+static gboolean
+widget_has_accel (GtkWidget       *widget,
+		  GtkAccelGroup   *accel_group,
+		  guint           key, 
+		  GdkModifierType mods)
+{
+	int i;
+	guint n_entries;
+	GList *l_tmp, *l_closures = gtk_widget_list_accel_closures (widget);
+	GtkAccelGroupEntry *entry = gtk_accel_group_query (accel_group,
+							   key, mods,
+							   &n_entries);
+
+	if (n_entries)
+		for (l_tmp = l_closures; l_tmp; l_tmp = l_tmp->next)
+	  		for (i=0; i<n_entries; i++) 
+			  	if (entry[i].closure == l_tmp->data) 
+			  	{
+					g_list_free (l_closures);
+					return TRUE;
+				}
+	
+	g_list_free (l_closures);
+
+	return FALSE;
+}
+
 static void
 impl_bonobo_ui_sync_menu_state (BonoboUISync *sync,
 				BonoboUINode *node,
@@ -392,11 +419,12 @@ impl_bonobo_ui_sync_menu_state (BonoboUI
 		if (!key) /* FIXME: this looks strange */
 			return;
 
-		gtk_widget_add_accelerator (menu_widget,
-					    "activate",
-					    sync_menu->accel_group,
-					    key, mods,
-					    GTK_ACCEL_VISIBLE);
+	  	if (! widget_has_accel (menu_widget, sync_menu->accel_group, key, mods))
+			gtk_widget_add_accelerator (menu_widget,
+						    "activate",
+						    sync_menu->accel_group,
+						    key, mods,
+						    GTK_ACCEL_VISIBLE);
 	}
 
 	bonobo_ui_engine_queue_update (
Comment 11 Cecilia Gonzalez 2006-08-28 13:00:52 UTC
Comment on attachment 71499 [details] [review]
Avoid the useless adding of menu accelerators. 

Edited! It had a problem of memory leaking.
Comment 12 André Klapper 2006-08-28 13:30:38 UTC
cecilia, this means that this has to get into CVS again, right? :-)
(asking because hardcode freeze will take place today at 23:59UTC)
Comment 13 Cecilia Gonzalez 2006-08-28 14:00:37 UTC
Andre, 
yes, it should be re-commited. 
Comment 14 Federico Mena Quintero 2006-08-29 01:17:45 UTC
Committed!  Thanks for the fix, Cecilia.