Re: [Vala] Gdk.RGBA in text tag - possible leak?



From: Gilzad Hamuni <gilli4 gmx net>
To: Vala-list <vala-list gnome org>
Sent: Monday, 18 May 2015, 16:16
Subject: Re: [Vala] Gdk.RGBA in text tag - possible leak?

 Gesendet: Montag, 18. Mai 2015 um 16:12 Uhr
 Von: "Al Thomas"
 As a hint I would try removing 'weak':

 Gdk.RGBA tmpColor = Gdk.RGBA();

Thanks Al,

if I understand correctly, then there's no use for 'weak' there as 
the scope for that declaration ends with the program. But it doesn't affect 
the memory consumption in the loop. I really went ahead and removed it now just 
to be sure. 


Hmm, Vala memory management is scope based reference counting. See
https://wiki.gnome.org/Projects/Vala/Tutorial#Destruction

So a program such as

void main() {
        int    count =    0;
        while ( count < 10 ) {
                var a =    new test();
                count++;
            } 
} 

class test {
        ~test() { print( "instance removed, memory freed\n" ); }
}


will have the destructor called on each iteration of the loop.

So I don't understand why your code in the loop after the comment
//when done, delete everything
is necessary. Or why you are using weak parameter types (generics) in Gee.ArrayList.
I'm wondering if you have over-engineered your program a bit because you have read
about weak and unowned and not grasped how nice Vala reference counting can be.

You may still have found a bug, but try refactoring your code a bit more first.


Still reading from "tag.foreground_rgba" consumes more > memory through the loop.

to_string() doesn't just read, it will need memory to create the string. I believe this should be freed when 
it goes out of scope, hopefully a bit 
more refactoring will resolve this.

All the best,

Al


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