Re: gtk_widget_destroy, gtk_object_destroy
- From: Sven Neumann <sven gimp org>
- To: Esteban Quijano Vincenzi <Esteban Quijano artinsoft com>
- Cc: gtk-list gnome org
- Subject: Re: gtk_widget_destroy, gtk_object_destroy
- Date: 06 Aug 2001 23:11:51 +0200
Esteban Quijano Vincenzi <Esteban Quijano artinsoft com> writes:
> What's the difference between gtk_widget_destroy and gtk_object_destroy? I
> guess every widget should be deallocated with gtk_widget_destroy and not
> with gtk_object_destroy, so, why there is no gtk_window_destroy,
> gtk_ctree_destroy, etc? Do they call a background destructor?
from gtkwidget.c:
void
gtk_widget_destroy (GtkWidget *widget)
{
g_return_if_fail (widget != NULL);
g_return_if_fail (GTK_IS_WIDGET (widget));
g_return_if_fail (GTK_OBJECT_CONSTRUCTED (widget));
gtk_object_destroy ((GtkObject*) widget);
}
so all you get with gtk_widget_destroy() is the additional
GTK_IS_WIDGET (widget) check since gtk_object_destroy calls
g_return_if_fail (GTK_OBJECT_CONSTRUCTED (object)) again.
In short: there is no real difference.
> What are gtk_widget_ref and gtk_widget_unref for? How are them related to
> gtk_widget_destroy?
widget_ref and widget_unref increase and decrease the reference count
of the widget. If the reference count drops to zero, the widget is
destroyed. The gtk_widget_destroy() function is a wrapper that calls
gtk_object_destroy(). To fully understand gtk_object_destroy(), I'd
suggest you read http://developer.gnome.org/doc/GGAD/cha-objects.html
and in particular http://developer.gnome.org/doc/GGAD/sec-finalization.html.
> Can we gtk_object_ref a widget and gtk_widget_unref it? Because it seems it
> is possible.
gtkwidget.h:# define gtk_widget_unref gtk_object_unref
gtkwidget.h:# define gtk_widget_ref gtk_object_ref
these are just stupid wrappers around the gtk_object functions.
> Should we use gtk_widget_ref - gtk_widget_unref or gtk_object_ref -
> gtk_object_unref in every GTK program?
I suggest using the gtk_object variants only since you avoid to suffer
from serious brain damage by doing so. The wrappers are just making
everything even more complicated.
> When we call gtk_main_quit what happen to all deallocated widgets? Is it
> wrong to call gtk_widget_destroy after gtk_main_quit?
it shouldn't hurt since all signal functions are synchronous and do not
depend on the main loop running.
Salut, Sven
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]