Re: g_free() vs gtk_widget_destroy()



Fabio Zanetta wrote:

Hi,

I cannot understand the difference between  g_free() and
gtk_widget_destroy().

g_free() frees raw memory allocated with g_new(). gtk_widget_destroy() marks a widget for destruction when its reference count reaches zero. It also emits a "destroy" that is meant to any reference holders to a to drop the reference it's holding. A widget wont be destroyed until its reference count drops to zero.

Someone can tell me this?
(btw: I have always to call gtk_widget_destroy()? I see for example that in
the Hello World in the GTK tutorial it is not used.)

Yes it is. It is in the following line of code (helloworld.c)

g_signal_connect_swapped (G_OBJECT (button), "clicked",
                          G_CALLBACK (gtk_widget_destroy),
                          window);

This connects the button's clicked signal directly to the gtk_widget_destroy() function, passing gtk_widget_destroy() window as it's argument. When you click the button the window gets destroyed.


Jeff Franks.




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