Re: GObject and reference counting?



On 15 Jan 2001, Havoc Pennington wrote:

> 
> Darren Kenny <Darren Kenny ireland sun com> writes:
> > 
> > GtkObject has the concept of a floating object, that could be 'new'ed and then
> > the initial reference count 'sink'-ed using gtk_object_sink... does any one
> > know if there is any intention to introduce this concept into GObject - it
> > would certainly be useful in the managing of memory.
> > 
> 
> Not currently planned - the rationale is that the "floating" concept
> only makes sense for objects that are definitely going to have a
> "long-term owner." For example, a widget will be placed in a
> container. The oddness that results otherwise is that you leak objects
> that don't ever get passed to an owner that sinks them.
> 
> The other problem is that a bunch of things that are GObject-derived
> now used to be plain refcounted, so stuff would break if they started
> floating. (This could be worked around with a ref/sink in the
> constructor, but a rule more complicated than "widgets have floating
> state, other objects don't" could be hard for people to follow.)

well, it should be note that GParamSpecs are floating as well, that's
done because they usually are just passed in to
g_object_class_install_property() and don't need to be further reference
counted explicitely by users.
the same thing applies to GClosure.
if people need non-widget objects that are floating, simply derive your
MyFloating object from GObject and add a floating flag plus
my_floating_sink() API to it like GtkObject does it.


> 
> Havoc
> 

---
ciaoTJ





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