GtkEv overrides only the
destroy method from
GtkObject, to clean up
the event description buffer. The widget's windows will
be destroyed in GtkWidget's
shutdown method, which unrealizes the widget. GtkWidget's finalize method
cleans up some GtkWidget
resources and then chains to the GtkObject method which frees the
instance struct. (Refer to the section called Object
Finalization in the chapter called The GTK+
Object and Type System for more details on
these methods.)
Because GtkEv has no object
arguments, it does not need to implement get_arg or set_arg methods.
Here is its destroy method implementation:
static void
gtk_ev_destroy (GtkObject *object)
{
GtkEv* ev;
GList* tmp;
g_return_if_fail(object != NULL);
g_return_if_fail(GTK_IS_EV(object));
ev = GTK_EV(object);
tmp = ev->buffer;
while (tmp != NULL)
{
g_strfreev((gchar**)tmp->data);
tmp = g_list_next(tmp);
}
g_list_free(ev->buffer);
ev->buffer = NULL;
ev->buffer_end = NULL;
ev->buffer_size = 0;
/* Chain up */
if (GTK_OBJECT_CLASS(parent_class)->destroy)
(* GTK_OBJECT_CLASS(parent_class)->destroy) (object);
}
|
The only detail worthy of note is that freed pointers
are set to NULL,
because a destroyed object should remain "sane," unlike
a finalized object. The
GtkEv code depends on the fact that destroyed
widgets are always unrealized; otherwise, text could be
re-added to the buffer after destruction but before
finalization, and a finalize method would be required.