#include <gtk/gtk.h>
#include <glib/gprintf.h>

void weak_ref_cb(gpointer data, GObject *obj)
{
	g_printf("Object destroyed: %p\n", obj);
}

gint main (gint argc, gchar *argv[])
{
	gtk_init(&argc, &argv);

	GtkWidget *items[3];

	GtkBox *box = (GtkBox *) gtk_vbox_new(FALSE, 0);

	items[0] = gtk_menu_item_new();
	items[1] = gtk_menu_item_new_with_label("_Test");
	items[2] = gtk_menu_item_new();
	gtk_menu_item_set_label((GtkMenuItem *) items[2], "_Test");

	guint i = 0;
	for (i = 0; i < G_N_ELEMENTS(items); i++)
	{
		g_printf("%p refcount: %d\n",
			items[i], G_OBJECT(items[i])->ref_count);

		g_object_weak_ref(items[i], weak_ref_cb, NULL);
		gtk_container_add((GtkContainer *) box, (GtkWidget *) items[i]);
	}

	for (i = 0; i < G_N_ELEMENTS(items); i++)
		gtk_container_remove((GtkContainer *) box, (GtkWidget *) items[i]);

	return 0;
}
