Re: GObject Destruction



Il Tue, 18 Dec 2012 21:49:13 +0100 David Nečas <yeti physics muni cz> scrisse:
> 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?

By exposing only dispose() and internalizing finalization in
libgobject. I'was just curious if an hypothetical new libgobject
would be implemented in the same way.

> (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.

We are saying the same thing: if a dynamic string is protected
against NULL throughout your code (no "special" protection
intended here), freeing and nullifying it in dispose() or freeing
in finalize() gives the same final result.

The dispose() propose sparkled from a specific request. I still
consider it a better approach than duplicating information. I
condider anything (with "anything" including globals, if
applicable) much better than duplicating.

A cleaner solution would be to implement a getter in the parent
object that returns X,Y by directly accessing the fields in the
instance struct (hence not passing throught the gobject property
mechanism). In this case using finalize() would be acceptable.

Ciao.
-- 
Nicola


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