[Vala] Property getters and memory management



As mentioned in an other thread, I'm considering to change property
getters to transfer ownership by default. While the current behavior
works fine in many cases, in some cases it does not work at all and can
cause bugs in the resulting application or library.

Whenever you want to return a constructed - instead of stored - string
or object, the property getters need to transfer ownership, which is
only possible with an unintuitive syntax in Vala 0.5.3 and earlier.

As I understand that Vala libraries, that are used from C, might not
want to return an owned value from property getters in most cases, we
will certainly continue to support this without restrictions.

However, if we change the default, it will be necessary to add an extra
modifier to the property declaration to retain the current behavior and
ABI. The same modifier will be used for bindings as well, of course.

An example for the proposed syntax to keep current behavior:

        public string foo { unowned get; set; }

weak/unowned in front of the property type will _not_ change the return
value of the getter and is only used to specify ownership of the
generated field for automatic properties.

Any comments on this proposal?

Jürg




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