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

Re: Chaining of dispose and finalize



On 09/04/04 00:04, Russell Shaw wrote:
> Jeff Franks wrote:
> >Russell Shaw wrote:
> >
> >>Hi,
> >>
> >>I made an object (View) derived from GObject.
> >>
> >>I overide the parent dispose and finalize pointers:
> >>
> >>
> >>static void
> >>view_class_init(ViewClass *klass)
> >>{
> >>    parent_class=g_type_class_peek_parent(klass);       // static
> >>
> >>    GObjectClass *gobject_class=G_OBJECT_CLASS(klass);
> >>    ViewClass *view_class=VIEW_CLASS(klass);
> >>
> >>    gobject_class->dispose=view_dispose;
> >>    gobject_class->finalize=view_finalize;
> >>...
> >>}
> >>
> >>
> >>This means the next two functions should call g_object_real_dispose()
> >>and g_object_finalize():
> >>
> >>
> >>static void
> >>view_dispose(View *view)
> >>{
> >>    if(view->dispose_has_run)
> >>        return;
> >>    view->dispose_has_run=TRUE;
> >>}
> >>
> >>static void
> >>view_finalize(View *view)
> >>{
> >>}
> >>
> >>
> >>But how do i do that when g_object_real_dispose() and g_object_finalize()
> >>are both declared static in gobject.c ?
> >
> >
> >With lines like these to call the parent (i.e. GObject) functions in 
> >view_dispose():
> >
> >G_OBJECT_CLASS (parent_class)->dispose (view);
> 
> But in view_class_init() above, i did: gobject_class->dispose=view_dispose,
> so G_OBJECT_CLASS(parent_class)->dispose(view) will recursively call itself
> forever.
> 
> >and in view_finalize():
> >
> >G_OBJECT_CLASS (parent_class)->finialize (view);
> 
> So will this.

no, it won't.  parent_class is a static version of the XXClass struct (where
"XX" is the name of the class your object is inheriting from).  gobject_class
is the static version of _your_ ViewClass struct (casted to its base type,
the GObjectClass).  they are two different instances (in fact, two different
types).

	-brian


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