Re: GObject destruction



David Necas (Yeti) wrote:

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.

My question is really about how to check for multiple invocation, without having to add a 'dispose' attribute to every class or subclass I write, if that is possible somehow. Gtk+ seems to make the parent GtkObject or GtkWidget class handle the dispose, then the subclasses do some magic, but they don't have a 'dispose' attribute,
AFAICT.

//Jacob




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