GNOME Bugzilla – Bug 592391
Gtk2::MenuItem leaks in some cases
Last modified: 2010-03-29 13:52:18 UTC
Created attachment 141193 [details] test case A Gtk2::MenuItem (and Gtk2::CheckMenuItem ...) created with my $item=Gtk2::MenuItem->new('sometext'); will not be automatically destroyed unless it has been added to a menu. This does not happen if the Gtk2::MenuItem has been created with : my $item=Gtk2::MenuItem->new; even if a label is added afterward. You might say that menuitem are almost always added to a menu :) But in the case of menuitem used as proxy_menu_item for a Gtk2::ToolItem, the menuitem won't be destroyed unless the menuitem has been added to the overflow menu.
I think this is dodginess in Gtk itself. A new_with_label makes an GtkAccelLabel with its "accel-widget" set to the item, which is a circular reference between the item and label. Sample accel.pl attached. I suppose the circularity is normally undone by a destroy() on the top GtkMenu calling destroy on all its children and sub-children. Needing to call $item->destroy from perl is unpleasant, but I suppose it's not a bug strictly speaking. We've got notes in Gtk2::Window on the need for explicit destroy() there. Perhaps a similar bit in Gtk2::MenuItem, and a cross reference in Gtk2::AccelLabel. I might have a go at a few words if no-one beats me to it.
Created attachment 156519 [details] sample circular ref between MenuItem and AccelLabel
Created attachment 156579 [details] [review] docs of MenuItem circular ref I got to these few words, plus test cases exercising the truth of the words :-).
Patch committed. Thanks! Since this is not a bug in the bindings, I'm marking this report accordingly.