Re: GObject Destruction



On Tue, Dec 18, 2012 at 08:45:42PM +0100, Nicola Fontana wrote:
> I always wondered if this double step finalization is hystorical
> craft. Why not drop finalize() altogether and avoid double dispose
> calls directly from libgobject?

The purpose of dispose() is to break reference cycles, i.e. to ensure
the object stops holding references to other objects.  You can free
other stuff there if it does not cause troubles but that is not the
purpose.

While you are breaking reference cycles all the object involved must
still be alive.

I'm not sure whether multiple executions of dipose() can occur in a
single-threaded program (see the source if you can understand).  But
how would break reference cycles when, for instance, a GtkWindow is
destroyed in a single-step finalisation method?

(Disclaimer: I'm not a GLib developer neither I can read the mind of
any.)

> You'd need to protect your code from NULLs

But I don't need to, that is the point (or, almost never need).  In my
obects I find that, normally, members unreferenced and nullified in
dispose() are those that can be NULL anyway so there is no special
protection against NULL related only to destruction.

Regards,

Yeti



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