Sign up

Doubt about Pixbuf (Memory Leak?)

Hi, First time here!

Well in a certain amount of time I need to copy a small region from screen.

I already tried too ways:

pixbuf = new Pixbuf(window, x, y, width, height);

and

pixbuf = Pixbuf.getFromDrawable(window, null, x,y, 0, 0, width, height);

Both ways works great, but the problem is the memory which doesn't stop to increase. Anyone had any problem like this? There is another way to copy regions from screen?

Re: Doubt about Pixbuf (Memory Leak?)

On Fri, 31 Oct 2014 21:25:56 GMT, MatheusBN wrote:

Both ways works great, but the problem is the memory which doesn't stop to increase.

Just a note: I was able to minimize the problem using this code:

if(!(pixbuf is null)){
    pixbuf.unref();
    delete pixbuf;
}

pixbuf = new Pixbuf(dr, x, y, w, h);


PS: Which I've found here: dsource

Matheus.

Re: Doubt about Pixbuf (Memory Leak?)

The problem in this case is that getFromDrawable already sets the
reference count as a convenience. So when GtkD wraps the object and adds
an reference the object, it is kept in memory indefinably because GtkD
now holds two references.

Re: Doubt about Pixbuf (Memory Leak?)

On Sat, 01 Nov 2014 17:07:33 +0100, Mike Wey wrote:

The problem in this case is that getFromDrawable already sets the
reference count as a convenience. So when GtkD wraps the object and adds
an reference the object, it is kept in memory indefinably because GtkD
now holds two references.

Right, but may a ask you (since I think you're one of the developer of the gtkD ) if there is a problem to create a destructor in Pixbuf.d module like this:

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

Because I'm using that and it worked fine, but I don't know what would be the consequences in the project.

PS: Sorry my english.

Matheus.

Re: Doubt about Pixbuf (Memory Leak?)

On 11/02/2014 03:51 PM, MatheusBN wrote:

On Sat, 01 Nov 2014 17:07:33 +0100, Mike Wey wrote:

The problem in this case is that getFromDrawable already sets the
reference count as a convenience. So when GtkD wraps the object and adds
an reference the object, it is kept in memory indefinably because GtkD
now holds two references.

Right, but may a ask you (since I think you're one of the developer of the gtkD ) if there is a problem to create a destructor in Pixbuf.d module like this:

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

Because I'm using that and it worked fine, but I don't know what would be the consequences in the project.

PS: Sorry my english.

Matheus.

That would work for this case but in other cases you would get an double
free error from GTK+.