This is the latest version I came up with:
To gtkD/src/gdk/Pixbuf.d I added the dtor as suggested by Matheus:
~this()
{
this.gdkPixbuf = null;
this.unref();
}
In gtkD/src/gtk/Image.d I inserted a line to setFromPixbuf:
public void setFromPixbuf(Pixbuf pixbuf)
{
// void gtk_image_set_from_pixbuf (GtkImage *image, GdkPixbuf *pixbuf);
if (pixbuf !is null) gtk_image_set_from_pixbuf(gtkImage, null); // this line is new
gtk_image_set_from_pixbuf(gtkImage, (pixbuf is null) ? null : pixbuf.getPixbufStruct());
}
My cbTimer looks like this now:
private bool cbTimer()
{
auto filename = this.filenames[this.filenameIdx];
if (++this.filenameIdx >= this.filenames.length) this.filenameIdx = 0;
if (this.pixbuf) {
// must not forget this to avoid memory leak
this.pixbuf.destroy();
}
this.pixbuf = new Pixbuf(filename);
this.image.setFromPixbuf(this.pixbuf);
// stop after 19 image switches to avoid out of memory
return ++this.iteration <= 19;
}
Now the program doesn't leak the Pixbuf buffer any more and there's no assertion failure messages any more.
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.
Tell me one thing: Are you using getPixbuf() somewhere in your code? If no, how are you displaying the image?
No. I create the Pixbuf from the file and set the Image to use this Pixbuf, just as in the full code in my previous posts or the cbTimer code snippet above. In my real code, there's various operations on the Pixbuf before it's given to the Image.
Diez