Re: [Vala] Property getters and memory management
- From: "Ali Sabil" <ali sabil gmail com>
- To: "Jürg Billeter" <j bitron ch>
- Cc: vala-list gnome org
- Subject: Re: [Vala] Property getters and memory management
- Date: Fri, 19 Dec 2008 17:22:31 +0100
On Fri, Dec 19, 2008 at 1:29 PM, Jürg Billeter
<j bitron ch> wrote:
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?
I am not entirely sure about the use of "owned" property getters, I think the default should remain "unowned", not that it is better, but to remain consistent with the established conventions in the C/GObject world, and avoid confusion. Also, from my experience, the use of "owned" properties is pretty limited. So the syntax I am proposing for it is:
public string foo { owned get; set; }
What do you think about it?
--
Ali
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]