FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Pixbuf Memory Consumption Issue

 
Post new topic   Reply to topic     Forum Index -> gtkD
View previous topic :: View next topic  
Author Message
zane.sims



Joined: 07 Aug 2007
Posts: 40

PostPosted: Sat Feb 13, 2010 4:36 pm    Post subject: Pixbuf Memory Consumption Issue Reply with quote

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
View user's profile Send private message
jpf2



Joined: 15 Aug 2009
Posts: 7

PostPosted: Sun Feb 14, 2010 4:09 am    Post subject: Reply with quote

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
View user's profile Send private message
zane.sims



Joined: 07 Aug 2007
Posts: 40

PostPosted: Sun Feb 14, 2010 6:50 am    Post subject: Reply with quote

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
View user's profile Send private message
Mike Wey



Joined: 07 May 2007
Posts: 428

PostPosted: Sun Feb 14, 2010 10:03 am    Post subject: Reply with quote

Code:
ObjectG.unref(pixbuf.getPixbufStruct());


Or when using svn:

Code:
pixbuf.unref();
Back to top
View user's profile Send private message
zane.sims



Joined: 07 Aug 2007
Posts: 40

PostPosted: Sun Feb 14, 2010 10:52 am    Post subject: Reply with quote

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
View user's profile Send private message
dsimcha



Joined: 24 Oct 2008
Posts: 16

PostPosted: Tue Jul 20, 2010 9:18 pm    Post subject: Reply with quote

Mike Wey wrote:
Code:
ObjectG.unref(pixbuf.getPixbufStruct());


Or when using svn:

Code:
pixbuf.unref();


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
View user's profile Send private message
Mike Wey



Joined: 07 May 2007
Posts: 428

PostPosted: Wed Jul 21, 2010 12:49 pm    Post subject: Reply with quote

Eventually it's going to integrated nicely.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> gtkD All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group