Re: What to do with private structure when object is destructed?g_type_class_add_private




On Tue, 2007-11-06 at 13:19 +0100, Tomasz Jankowski wrote:

I added private structure to my class using g_type_class_add_private . When
object is destructed I need to free memory allocated by this structure on my
own in XXX_finalize method or GType will for me?

since you're not explicitly allocating it by yourself, then you should
not free it. you should, obviously, free any allocated memory you are
holding inside the private data structure - so:

  static void
  my_foo_object_finalize (GObject *gobject)
  {
    MyFooObjectPrivate *priv = MY_FOO_OBJECT_GET_PRIVATE (gobject);

    g_free (priv->an_allocated_string);
    my_bar_struct_free (priv->an_allocated_struct);

    G_OBJECT_CLASS (my_foo_object_parent_class)->finalize (gobject);
  }

ciao,
 Emmanuele.

-- 
Emmanuele Bassi,
W: http://www.emmanuelebassi.net
B: http://log.emmanuelebassi.net




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