Re: [Vala] reference management.



On Die, 2007-03-20 at 10:17 -0300, Alexandre Moreira wrote:
I think it would be just great to allow the user to specify an "expert
mode" and allow him to do the ref unref by himself (just like GObject
does, giving G.Object a method to do each action) and, at most, having
the auto-unref-local-variables-unless-specified-otherwise.

Basically it would mean the addition of the ref/unref methods and an
option to set all references to weak.

You can disable automatic memory management in vala by using the
--disable-memory-management command-line option. I've also added ref and
unref methods to GLib.Object, so you can leak as much memory as you want
now ;)

I know *I* (and I know it doesn't mean much) would prefer working like
this. The more automatic behavior the more unpredictible or complex
are the rules to define "how each case is handled" and I believe these
unpredictible or complex rules create more of a mental effort to the
programmer than the activity of handling its own references.

The unpredictability / complex behavior is the reason why I've just
disabled the heuristic in Vala SVN; local variables also default to
strong references. So the rules are now very simple and you can use weak
wherever you want to improve performance if you understand reference
handling of GObjects. I believe that using automatic memory management
will lead to easier readable code and less bugs, so I won't recommend to
use the --disable-memory-management option. If you still want to work
with disabled automatic memory management, I'd be interested in further
explanations why, to possibly improve the default behavior further.

Jürg




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