Re: GObject: Freeing memory of instance members?

On 5/3/07, Øystein Johansen <oystein gnubg org> wrote:
David Nečas (Yeti) wrote:
> On Thu, May 03, 2007 at 10:40:17PM +0200, ??ystein Johansen wrote:
>> Aha, but how/where to I set the pointer to the finalize() function?
> In my_class_init() where you override all other methods.
> See (almost) any Gtk+ widget for examples.

Aha again! I guess I can free private members in the same method as well?

static void
neural_net_finalize (GObject *object)
  NeuralNet *nn;

  g_return_if_fail (IS_NEURAL_NET(object));

  nn = NEURAL_NET(object);


  g_message("This is the finalize method and I've freed the instance


static void
neural_net_class_init (NeuralNetClass *klass){
        GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
        gobject_class->finalize = neural_net_finalize;
        g_type_class_add_private (klass, sizeof (NeuralNetPrivate));

I think this looks ok, doesn't it? No, wait a minite.... What about the
parent? This class has GObjectClass as parent, how do I call it's finalize?

At your class_init you should peek (g_type_class_peek_parent, using
your class pointer as parameter) a pointer to your parent class and
keep it in a global storage, accessible to your finalize.

Then, in your finalize method you call the finalize method on this
pointer you just got from peek_parent, something like:


I hope this helps.
Alexandre Moreira.


gtk-list mailing list
gtk-list gnome org

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