Web lists-archives.com

Re: Floating references

On Tue, 06 Jun 2017 19:35:40 +0900
Tristan Van Berkom <tristan.vanberkom@xxxxxxxxxxxxxxx> wrote:
> On Tue, 2017-06-06 at 11:50 +0200, Stefan Salewski wrote:
> > But I was wondering, why for newly created objects ref count is not
> > just zero, so when the element is put into a container it is just
> > increased to one.  
> In a way, it already is.
> Whether it is the actual ref_count that is zero, or whether there is
> just a separate floating flag I think is quite immaterial; you need to
> have some state to mark the floating object after g_object_new()
> returns otherwise it is in an invalid state until the first call to
> g_object_ref().
> The fact that the count itself is 1, is mostly irrelevant.

I have to say that I have had the same thought as Stefan on this.  All
other intrusive pointer implementations I have seen start at a count
of 0 on creating an object, increment the count to 1 when that object
becomes first owned, and take the change of state from 1 to 0 on the
final unreference as indicating that the object concerned needs to be

Using a separate flag for the same initial purpose seems pointless: it
is a waste of space.  Possibly the original designer didn't want a count
of 0 to arise in two different circumstances (on creation and on the
final unreference), but that seems a bit weak.  Surely there must have
been some other reason for it?

gtk-list mailing list