Re: gtk_widget_destroy, gtk_object_destroy



Esteban Quijano Vincenzi <Esteban Quijano artinsoft com> writes:
> What's the difference between gtk_widget_destroy and
> gtk_object_destroy?

Nothing whatsoever. 

Implementation:

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);
}

gtk_widget_destroy() is from GTK 1.0, which had no GtkObject.
It exists for backward compat. Though it still isn't deprecated in GTK
2, just because it's not really worth deprecating, and it's sort of
convenient sometimes.
 
> What are gtk_widget_ref and gtk_widget_unref for? How are them related to
> gtk_widget_destroy?

gtk_widget_destroy() emits a signal which means "everyone should
please drop their reference counts." For widgets inside a container,
the parent container will drop a reference. For toplevel GtkWindow
widgets, GTK holds a reference that it will drop. If you haven't
called gtk_object_ref(), those references will typically be the only
references, and the widget will be finalized. (Finalized = actually
freed.)

> Can we gtk_object_ref a widget and gtk_widget_unref it? Because it seems it is
> possible.

Yes. gtk_widget_ref is also a holdover from GTK 1.0.

> Should we use gtk_widget_ref - gtk_widget_unref or gtk_object_ref -
> gtk_object_unref in every GTK program?

Either is fine.

> When we call gtk_main_quit what happen to all deallocated widgets? Is it wrong to
> call gtk_widget_destroy after gtk_main_quit?

No, there's no relation between widget lifecycle and the main loop.

Havoc




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