View previous topic :: View next topic |
Author |
Message |
zane.sims
Joined: 07 Aug 2007 Posts: 40
|
Posted: Sat Feb 13, 2010 4:36 pm Post subject: Pixbuf Memory Consumption Issue |
|
|
Hey all,
I have encountered a problem on a recent project of mine when using a pixbuf. I have need of loading many images in a loop where I would like to:
1) load the image
2) use the image
3) free the image
4) go to the next image in the loop and do the same thing
When I load the images in a pixbuf, I am not sure how to free the loaded data. I tried using "delete", but the system monitor still shows the memory skyrocketing. I was able to reproduce my problem with the following simple test code:
Code: | module test;
import gtk.Main;
import gdk.Pixbuf;
import gdkpixbuf.PixbufLoader;
import std.file;
import std.stdio;
int main(char[][] args)
{
Main.init(args);
Pixbuf pixbuf;
while(true)
{
if(readln == "exit\n")
break;
PixbufLoader pl = new PixbufLoader;
pl.write(cast(char[]) std.file.read("test.jpg") );
pixbuf = pl.getPixbuf;
pl.close;
//do stuff with pixbuf
//would like to free memory here
delete pixbuf;
}
return 0;
} |
Of course, the same image is re-loaded each time, but this is just a test app. What can I do to free the memory, or is this a problem with GtkD? I am using: DSSS v0.78, DMD v1.053, GtkD v1.3, Ubuntu Linux 9.10.
Any help is greatly appreciated!
Thanks in advance!
Zane _________________ わたしがプログラマだよ! |
|
Back to top |
|
|
jpf2
Joined: 15 Aug 2009 Posts: 7
|
Posted: Sun Feb 14, 2010 4:09 am Post subject: |
|
|
Maybe you have to unref the Object:
Code: | //would like to free memory here
ObjectG.unref(pixbuf) |
it might work, but I can't test it right now. |
|
Back to top |
|
|
zane.sims
Joined: 07 Aug 2007 Posts: 40
|
Posted: Sun Feb 14, 2010 6:50 am Post subject: |
|
|
Thanks for your reply, however, a Pixbuf is not a GObject, and therefore I get an assertion error when trying to pass it as a parameter to that function.
Other ideas?
Thanks again,
Zane _________________ わたしがプログラマだよ! |
|
Back to top |
|
|
Mike Wey
Joined: 07 May 2007 Posts: 428
|
Posted: Sun Feb 14, 2010 10:03 am Post subject: |
|
|
Code: | ObjectG.unref(pixbuf.getPixbufStruct()); |
Or when using svn:
|
|
Back to top |
|
|
zane.sims
Joined: 07 Aug 2007 Posts: 40
|
Posted: Sun Feb 14, 2010 10:52 am Post subject: |
|
|
Once again, you have saved me Mike - I truly appreciate it! jpf2, thanks for your help as well. You weren't too far off afterall.
Thanks!
Zane _________________ わたしがプログラマだよ! |
|
Back to top |
|
|
dsimcha
Joined: 24 Oct 2008 Posts: 16
|
Posted: Tue Jul 20, 2010 9:18 pm Post subject: |
|
|
Mike Wey wrote: | Code: | ObjectG.unref(pixbuf.getPixbufStruct()); |
Or when using svn:
|
Is the memory management of gtkD eventually going to get fully integrated into D's GC framework through finalizers, or will we forever have to worry about memory management as if we're programming in C even though we're programming in D? |
|
Back to top |
|
|
Mike Wey
Joined: 07 May 2007 Posts: 428
|
Posted: Wed Jul 21, 2010 12:49 pm Post subject: |
|
|
Eventually it's going to integrated nicely. |
|
Back to top |
|
|
|