Re: [Vala] Owned method parameters



On Wed, 2009-06-10 at 19:32 +0200, Jiří Zárevúcky wrote:
Hello, I've noticed a strange thing about the "owned" keyword.

It works differently (and completely uselessly) on method parameters,
then it does when assigning. I'm curious whether that's intentional.

It references the object in the call, and unreferences on the end of
the method. I really don't see why anyone would want to do that, as
weak parameter works exactly the same without the ref/unref overhead.
Even if it was intentional, to ensure lifetime of the passed object,
it would be IMHO better to reference it on the beginning of the
method, not in the call (it could confuse C programmer using the
class).

Anyway, I don't think it's wise to make the behavior different in
those two cases.

The behavior is quite consistent. Passing a value as a method argument
corresponds to assigning the value to a local variable (=> ref), and the
end of the method body corresponds to the end of the scope of a local
variable (=> unref).

Anyway, owned parameters are not intended to be used in Vala code. The
main use case is to make it possible to bind C libraries with unusual
memory management requirements. And in those cases we really need the
current owned parameter semantics, everything else will either leak or
crash.

Jürg




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