Re: tooltips and refcounts



On 2 Sep 1998, Owen Taylor wrote:

a few more words on this issue...

> Yet you _should_ be able to do that. One big point of the
> refcounting scheme is to make things easy on interpreted languages.
> The interpreted language ref's and sinks the widget upon creation.
> If, when the interpreted language loses its last refcount to
> the widget, the widget should be freed if it is not in the
> widget heirarchy.
> 
> There is a reason why we don't just create widgets with a reference
> count of 1 and decrement on destruction. But you seem to
> be saying that that would be OK behavior - i.e.:

we actually *do* create objects and widgets with a refcount of 1,
we just indicate through the floating flag that someone has to take
over responsibility for this refcount, since in the original gtk way,
parents took over responsibility for widgets when they were added
to them and applications were usually not aware of maintaining
a *child* widgets destruction anymore.
this is also the reason gtk takes over the floating flag for toplevels
automatically, on behalf of the application, since all applications
know they have to destroy toplevels explicitely.


>  * A widget won't be freed until someone calls gtk_widget_destroy()

this does in fact hold if you want to deal with objects in a generic
fashion (i.e. without implementing special knowledge about toplevels).
the following call sequence is mandatory to deal with objects and
their destruction in a generic way:

object = gtk_object_new (GTK_TYPE_[something], NULL);
gtk_object_ref (object);
gtk_object_sink (object);
[do stuffs to object]
gtk_object_destroy (object);
gtk_object_unref (object);

[i came across this when implementing a generic function to query
 default values for object arguments in GLE, which would apply to
 any kind of gtk objects]

> 
> Ugh.
> 
> Regards,
>                                         Owen
> 

---
ciaoTJ



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