Do I need to create popup menus in GTK?

This is the first time I use GTK. I have the following code, and I am wondering a memory leak. It is inside a function that is called every time a right-click occurs.

GtkWidget *menu = gtk_menu_new();

//while loop adding a bunch of menu items
gtk_menu_shell_append(GTK_MENU_SHELL(menu), menu_item);

gtk_widget_show_all(menu);
gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, 3, event->button.time);

Is cleanup processed automatically by GTK?

+4
source share
1 answer

GtkMenuas your code shows, is a subclass GtkWidget, which in turn is a subclass GInitiallyUnowned. So it has everything that floats-ref magic around.

, , GtkWindow, , , , .

: , , .

, :

g_object_ref_sink(menu); //ref = 1
g_menu_popup(...);
g_print("I am %s\n", menu->ref_count==1? "right" : "wrong");
g_object_unref(menu);

: ref_count , ! GObject .

+3

Source: https://habr.com/ru/post/1526595/


All Articles