Should I chain up finalize?

View: New views
2 Messages — Rating Filter:   Alert me  

Should I chain up finalize?

by 一首诗 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I found code like this in gio

static void
g_filter_input_stream_finalize (GObject *object)
{
  GFilterInputStream *stream;

  stream = G_FILTER_INPUT_STREAM (object);

  g_object_unref (stream->base_stream);

  G_OBJECT_CLASS (g_filter_input_stream_parent_class)->finalize (object);
}

It looks like I should also use
  G_OBJECT_CLASS (xxxxx_parent_class)->finalize (object);
to chain up instance finalize in my code.

BUT, I found that it caused parent class's finalize called twice when unref.

So, should I or should I NOT chain dispose and finalize in my code?

BTW : I think this should be clarified in Gobject's tutorial.

--
look to the things around you,the immediate world around you, if you are alive,it will mean something to you ——Paul Strand

_______________________________________________
gtk-list mailing list
gtk-list@...
http://mail.gnome.org/mailman/listinfo/gtk-list

Re: Should I chain up finalize?

by David Nečas (Yeti)-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Fri, Oct 23, 2009 at 11:22:20AM +0800, Peter Cai wrote:

> I found code like this in gio
>
> static void
> g_filter_input_stream_finalize (GObject *object)
> {
>   GFilterInputStream *stream;
>
>   stream = G_FILTER_INPUT_STREAM (object);
>
>   g_object_unref (stream->base_stream);
>
>   G_OBJECT_CLASS (g_filter_input_stream_parent_class)->finalize (object);
> }
>
> It looks like I should also use
>   G_OBJECT_CLASS (xxxxx_parent_class)->finalize (object);
> to chain up instance finalize in my code.

Yes, you have to chain finalize and dispose and dispose can be called
more than once (but not finalize).

> BUT, I found that it caused parent class's finalize called twice when unref.

It cannot.  Post a simple code example demostrating finalize is called
twice.

> BTW : I think this should be clarified in Gobject's tutorial.

    http://library.gnome.org/devel/gobject/stable/gobject-memory.html

[cite]
Finalize is expected to complete the destruction process initiated by
dispose. It should complete the object's destruction. finalize will be
executed only once. finalize should chain up to its parent
implementation just before returning to the caller.
[/cite]

What is unclear on that?

Yeti

_______________________________________________
gtk-list mailing list
gtk-list@...
http://mail.gnome.org/mailman/listinfo/gtk-list