Re: glib ref counting problem



Hi Tristan,

at first thans for listening and suggesting!

I think I follow path a) plus using weak_pointers. Anyway, as destoying the song
will cause destruction of the childs (setup, pattern) this is just a matter of
safety (to aid debugging).

version b.) is not so appropriate here as e.g. only the song might know what
needs to be passed to construct the child objects.

oh yes, oo-design can be tricky :-)

Stefan

PS.: anyway, the code is in the CVS of http://www.buzztard.org
PS.: I need a fulltext search for gnome sources ;-)
Tristan Van Berkom wrote:
Stefan Kost wrote:
[...]

unfortunately there are no explicit docs for the behaviour, but in
set_property
method receiving a pointer needs to be secured. I will now try to
switch to
add_weak_pointer(). One thing I dont get about this function is why I
have to
pass the object and then the pointer to my weak pointer. In practice
it will
look like:
myobject=object;
g_object_add_weak_pointer(myobject,&myobject);
Btw.: the docs should say, that the method does not initialize the passed
pointer to point to object.

same for
 g_object_remove_weak_pointer();

... I am drifting away ;-)
Anyway, I hope that this is the recommended way of doing these things,
as I will
update the GObject tutorial soon.


I think I understand your quandry now.

    You want the delagate object (BtPattern/BtSetup) to have the
parenting/owning object (BtSong) as a "property". If you want my
"recommendation", IMO this is backwards in principal. You would avoid
alot of trouble if either:

   a.) BtSong is created with a sufficient amount of args/properties
       to create and own a delagate object where that object doesn't
       need to reference BtSong directly.

   b.) The delagate object (BtPattern/BtSetup) are created first
       and then used to construct a BtSong (i.e. BtPattern/BtSetup
       are properties of BtSong). Much in the same way that:

       adjustment = g_object_new(GTK_TYPE_ADJUSTMENT, ...);
       vscale = g_object_new(GTK_TYPE_VSCALE,
                             "adjustment", adjustment, ...);

Is that a little closer to the mark ?

Cheers,
                                       -Tristan



-- 
http://www.buzztard.org


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