RE: Release memory for a GtkWindow



Title: RE: Release memory for a GtkWindow

The example code I put on my first name was created by Glade.
So if I understand correctly, I just need to put

        GtkWidget * button = gtk_button_new ();
        gtk_widget_set_name (button, "button");
        gtk_widget_show (button);
        gtk_object_set_data_full (GTK_OBJECT (window), "button", button, (GtkDestroyNotify) gtk_widget_unref);
        gtk_container_add (GTK_CONTAINER (window), button);


-----Message d'origine-----
De : Havoc Pennington [mailto:hp redhat com]
Envoye : jeudi 14 mars 2002 14:50
A : mrl netbank com br
Cc : zze-coframi balr001; Mailing list GTK+ (E-mail)
Objet : Re: Release memory for a GtkWindow



mrl netbank com br writes:
> In this case would be better you call 2 times gtk_widget_unref(window)
> becose when you create it, it has ref count at 1, you referenced it, so it's
> at 2, and then you wanna delete, so 2 - 1 = 1   1 - 1 = 0, it's 2 times you
> have to call, becose you didn't release the reference of the builder
> function.

No! That isn't correct. When you create a window it has a ref count of
1, but that count is owned by GTK. You can't call unref(), you must
call gtk_object_destroy(), which will cause GTK to drop its count. If
you can unref() then GTK will segfault eventually.

In the example code I think gtk_object_destroy() on the window will
free everything, though I don't understand why the extra ref on the
child button is used, since containers ref their children anyway.

Havoc



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]