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

Re: whats the difference between dispose and finalizie?



On Sat, 2002-04-27 at 16:21, Havoc Pennington wrote:
> 
> rob <mailingLists@pangolin.org.uk> writes:
> > 
> > I'm trying to port may app to gnome2 but am stuck on how to destroy the
> > objects.
> > Firstly it seems that 
> > objectClass->destroy = myDestroyFunc
> > should change to 
> > objectClass->finalize = myDestroyFunc
> > but then there is an objectClass->dispose so perhaps destroy has just
> > changed name? Or dose the dispose function serve some other purpose?
> 
> IIRC dispose is like destroy, except that dispose is not a signal.
> There may be other small differences. The dispose method for GtkObject
> emits the destroy signal, and gtk_object_destroy() runs the dispose
> method.
> 

Thanks :) anything that used to be in destroy goes in dispose.
 
> > And secondly if my object is also a widget in stead of which ever of the
> > above is correct I have to go back to the old way of doing things and
> > overload GtkObject->destory and do all my destroying in there !?
> 
> The split between destroy and finalize is the same as for 1.2: destroy
> should break references between the object and other objects, or
> perhaps better phrased, destroy should return an object to its "new"
> state as if the object were just created, where it isn't holding
> references to other things. The purpose of destroy is to break
> reference count cycles.

What I mean't was that the porting doc makes it sound that if your
object is a widget then you shouldn't use gobjectClass->dispose but
gtkObjectClass->destroy.

 
> While finalize should actually free memory.
> 
> > <quote>
> > Also, ::destroy implementations have to release object references that
> > the object holds. Code in finalize() implementations such as:
> > 
> > if (object->adjustment) {
> >   gtk_object_unref (object->adjustment);
> >   object->adjustment = NULL;
> > }
> >                   
> > 
> > have to be moved into the ::destroy implementations.
> > </quote>
> 
> It's confusing that this is in the porting guide, since this was also
> true in 1.2 (this code should have been in destroy for 1.2 as well).

Ahh Ok. Thats what confused me I thought it was saying that in 2.0 this
code should be moved into gobjectClass->finalise unless you had a widget
in which case it should move back into gtkObjectClass->destroy.

> Havoc
>

Thanks :)
 
-- 

rob




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