Re: Should I chain up finalize?



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



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