Re: GObject destruction



On Sun, Feb 12, 2006 at 04:44:49PM +0100, Jacob Kroon wrote:
> I've read the GObject tutorial, and I'm trying to understand how to 
> implement the dispose/finalize
> functionality. They way I see it, the you need to override dispose in 
> GObjectClass, and that this
> method should g_object_unref() any objects which the instance uses, and 
> that finalize() should release
> any allocated memory etc. Dispose might be called more than once, so one 
> needs to guard against
> multiple invocations using some sort of flag. My question is, will every 
> class I create always need to have a
> DISPOSED attribute (for instance a flag, or an int) in order to 
> implement this correctly ?

Release only non-NULL references and always set referenced
object pointers to NULL when you release them.  This is
simple, consistent, and it works equally well when the
referenced objects may be unset or they may be set, unset,
and swapped arbitrarily during object's lifetime.

Yeti


--
That's enough.



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