[Vala] var does not honor weak?



Im pretty new to both glib/gobject and vala so I might be missing something,
but creating a weak reference is supposed not to create a new reference to the object it points to.

On the other hand var is supposed to guess the type of the reference, so one will not have to type it explicitly.
But when using var on functions, returning a weak reference the ref_count is increased with is not the case if the same if the same _expression_ is typed manually:

VALA:
using GLib;

public class WeakTest {
    static Object o = null;

    public static weak Object get_object () {
      o = new Object();
      return o;
    }

    static int main (string[] args) {
       
      weak Object localo = get_object();
      message("ref_count: %d",(int)localo.ref_count);
        return 0;
    }
}
RETURN:
** Message: weak_tst.vala:16: ref_count: 2
C-FILE:



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