Re: closure floating

On Wed, 17 Jan 2001, Karl Nelson wrote:

> > On 16 Jan 2001, Owen Taylor wrote:

> The simplest solution is don't have a floating state for closures.
> (Or rather any ref sinks them, thus there is no sink operation.)
> Once you create them the first time you use them they are destroyed
> unless you reference them yourself.  (This is equivalent to everything
> sinks.)

this is equivalent to ref_count==0 at startup, or floating+every-ref-sinks
as you say it. and it's exactly the behaviour we currently have in glib,
however owens (havocs) argument is that its yet another referencing
mechanism introduced, different from widgets which are floating initially,
or plain structures that are just ref/unref.

however - looking at owen's line of reasoning to have some functions
taking closures do sinking and others not, and that this is unlikely
to confuse normal users since closure usage is an advanced topic anyways -
i fail to see that having the current closure behaviour, though it is yet
another referencing scheme, will, in comparison, add more complexity.

startup ref_count==0/floating+every-ref-sinks is at least fully
predictable, no extra care has to be taken for connect vs. foreach,
or with your foobar() variant. and we're unlikely to end up leaking
while still catching errernerous user behaviour with ref_count!=0

>   void foobar(int p, GClosure*); /* does this eat the closure or not
>                                   or does that depend on p??? */
> Simple rule, if you create it and want to keep it, reference it!
> Second if they forgot the ref in the foreach case assuming they
> didn't create another closure in between, it will fail the
> assertion that ref!=0 when it goes to use it.
> --Karl


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