Re: [Vala] object leak in async and closure



Yes it is true, I'm sorry my fault. I'm rying your last fix


2014/1/4 Luca Bruno <lethalman88 gmail com>

I see "destroy pippo" with valac-0.22.


On Sat, Jan 4, 2014 at 9:28 PM, Michele Dionisio <
michele dionisio gmail com> wrote:

I will try, reading the comment on git it seams a problem introduced in
vala 0.23.1 but I have test also vala-0.22 and it have the same problem.


2014/1/4 Luca Bruno <lethalman88 gmail com>

I've just fixed the bug in vala git master, can you check?
Commit 550b107896


On Sat, Jan 4, 2014 at 7:56 PM, Luca Bruno <lethalman88 gmail com>wrote:

Please report a bug at bugzilla.gnome.org .
So, using "o" in the lambda seems to be the problem.


On Sat, Jan 4, 2014 at 7:39 PM, Michele Dionisio <
michele dionisio gmail com> wrote:

Hi, I'm new in this mailing list and quite new in vala programming.

I have a big software that somethime leak objct. Now I have replicate
the
issue with a small code:


############################################################################
    class Pippo: Object {
        public async void foo () {
            Object o = new Object ();
            stdout.printf("out-- %u\n",o.ref_count);
            stdout.printf("this -- %u\n",this.ref_count);

            SourceFunc f = () => {
                stdout.printf("infunc-- %u\n",o.ref_count);
                stdout.printf("in this -- %u\n",this.ref_count);
                //this.unref();
                stdout.printf("in this -- %u\n",this.ref_count);
                stdout.printf("end function f\n");
                return false;
            };
            GLib.Idle.add( (owned) f );

            stdout.printf("end function foo\n");
        }

        ~Pippo() {
            stdout.printf("destroy pippo\n");
        }
    }

    void main() {
        Pippo ? tmp = new Pippo();

        tmp.foo.begin();

        MainLoop loop = new MainLoop ();

        GLib.Timeout.add(1000, () => {stdout.printf("timeout1\n"); tmp
=
null; return false;});

        GLib.Timeout.add(2000, () => {stdout.printf("timeout2\n");
loop.quit(); return false;});


        loop.run ();
}


############################################################################

If in the function
SourceFunc f

there is any reference to any variable of foo or to any object of this
we
have the reference counting of this increase.

and so after timeout1 the object tmp is not destroy. (And there is no
reference on it)

The only way to fix the issue is to manually decrease the reference of
this. But this is a big workaraound.

Someone have any idea where is my fault or if there is a bug in vala
itself?

regards
_______________________________________________
vala-list mailing list
vala-list gnome org
https://mail.gnome.org/mailman/listinfo/vala-list




--
www.debian.org - The Universal Operating System




--
www.debian.org - The Universal Operating System





--
www.debian.org - The Universal Operating System



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