On Wed, 05 Nov 2014 04:57:25 GMT, Diez wrote:

gtkD's memory management should be fixed, because for me a D wrapper around a C library is exactly about not having to concern about memory management.

There's still some minor peculiar up and down in memory consumption in my real program though, but I didn't investigate yet where it comes from nor whether it grows over all.

Alright, I think that I found those GObject failures:

GLib-GObject-CRITICAL **: g_object_unref: assertion 'G_IS_OBJECT (object)' failed

In your code after you load the image with Pixbuf you set it to an Image type variable calling this.image.setFromPixbuf(), but then in the next loop interaction you are destroying the Pixbuf which is referenced by the image that you had set before.

To correct this problem I use image.clear() before destroying the Pixbuf!

So this is my drawImg() function with NO LEAKS and NO GOBJECT ERRORS:

void drawImg(Context cr){    
    static bool change = true;
            
    if(!(this.pixbuf is null)){
        this.pixbuf.unref();        
        delete pixbuf;
    }          
    
    auto fimg = change ? "teste.png" : "teste2.png";
    
    this.pixbuf = new Pixbuf(fimg);
    
    this.image.setFromPixbuf(pixbuf);        
    
    // I'm just using the next 3 lines to display on the screen
    auto pb = this.image.getPixbuf();       
    cr.setSourcePixbuf(pb, 0, 0);
    cr.paint();
    
    // THIS IS IMPORTANT TO AVOID GOBJECT ERRORS
    image.clear();
    
    change = !change;
}


Another important thing: I need to take off my dtor in Pixbuf.d:

~this(){
    //this.gdkPixbuf = null;
    //this.unref();
}

And as you can see in the code above I'm handling the unref locally, because in my example I'm using:

auto pb = this.image.getPixbuf()

The getPixbuf() calls the dtor (Maybe Garbage Collector?) causing an error.

I'll check later a way to correct this, maybe looking for any references alive etc.

Matheus.