Re: custom gtkwidget destruction



On Fri, Feb 25, 2011 at 7:57 AM, James Morris <jwm art net gmail com> wrote:
Hi,

I'm a little confused over destruction of my custom widgets. I'm
mainly looking at existing code for how to do things as I've found the
docs (via DevHelp) difficult to understand and to garner an idea of
when and what is needed.

Here's some typical code for one of the widgets which is (typically)
just a group of GtkWidgets:

--8<--
G_DEFINE_TYPE(EnvelopeTab, envelope_tab, GTK_TYPE_VBOX)

static void envelope_tab_destroy(GtkObject* object);
static void update_env(EnvelopeTabPrivate*);


static void envelope_tab_class_init(EnvelopeTabClass* klass)
{
   GtkObjectClass *object_class = GTK_OBJECT_CLASS(klass);

   object_class->destroy = envelope_tab_destroy;
   envelope_tab_parent_class = g_type_class_peek_parent(klass);

   g_type_class_add_private(object_class, sizeof(EnvelopeTabPrivate));
}


static void envelope_tab_destroy(GtkObject* object)
{
   GtkObjectClass* klass = GTK_OBJECT_CLASS(envelope_tab_parent_class);

   if (klass->destroy)
       klass->destroy(object);
}

--8<--

I am wondering if in this case, as there is no extra data to destroy,
is it really necessary for me to specify the destroy function?

Put another way, by specifying the destroy function, am I duplicating
by 'over-riding' the 'default destructor' and/or possibly omitting
things which should be done?

With regard to the docs, finalize and dispose are mentioned. Are these
only required if I explicitly need deeper control over the destruction
(of - in this case - the widgets my widget uses)?

  a.) You generally dont need to use ->destroy, just use ->dispose()
        for cases where you need to unref other objects that your
        object holds a reference to, and use ->finalize() to free any
        other data/resources.

  b.) If your widget does not allocate any resources, you dont need
        to define any dispose/finalize methods

Cheers,
    -Tristan



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