|
|
Choosing A Webhost: |
Gdk Pixbufloader not freeing memory: msg#00029gnome.gtk+.perl
I had a problem using the pixbufloader with Gtkperl. Basically the loader object doesn't seem to be releasing memory even when it is explicitly undef'd. I wrote a small test script to try to isolate the problem. It creates a window with a single button. Every time you click the button an image (hard coded in the script) will be loaded using the pixbufloader. If I run this program and watch the memory usage with top, I can see that the memory utilization for the script just keeps increasing. Has anyone seen this before? Is there a workaround? #!/usr/bin/env perl use Gtk::Gdk::Pixbuf; use Gtk; use IO::File; use warnings; use strict; # Set the name of the file to load my $file="/home/jforkey/temp/pictures/IMG_1242.JPG"; my $loader; Gtk->init(); # Make the GUI my $Win = Gtk::Window->new; my $box = Gtk::HBox->new(0,0); my $button1 = Gtk::Button->new("Load image"); $box->pack_start($button1, 0, 0, 0); $button1->signal_connect("clicked", \&load_image, $file); $Win->add($box); $Win->show_all; $Win->signal_connect("delete_event", \&Gtk::main_quit); Gtk->main(); # load 1k bytes from image file sub load_image_buf { my ($fh) = @_; my $buf; my $NumRead = sysread($fh,$buf, 1024); defined $NumRead or die "couldn\'t read\n"; if ($NumRead == 1024) { print "Writing $NumRead bytes to pixbuf loader\n"; $loader->write($buf); return 1; # leave function on the Gtk Idle execution loop } else { # last chunk of data from image print "Writing $NumRead bytes to pixbuf loader\n"; $NumRead and $loader->write($buf); print "closing pixbuf loader\n"; $loader->close; $loader = undef; # *** memory should be released here *** $fh->close; return 0; # take function off the Gtk Idle execution loop } } # Set up pixbufloader to load image. sub load_image { shift; # get rid of Gtk::Button object my ($name) = @_; # if we're already loading the image don't do anything $loader or do { # open file handle for image my $fh= IO::File->new($name, "r"); $loader= Gtk::Gdk::PixbufLoader->new; # every 100 ms execute load_image_buf to load another 1k bytes of the image Gtk->idle_add(\&load_image_buf, $fh); } }
|
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Re: editable cells in GtkListView, tom roth |
|---|---|
| Next by Date: | Re: drag and drop with clist, René Seindal |
| Previous by Thread: | editable cells in GtkListView, tom roth |
| Next by Thread: | Re: Gdk Pixbufloader not freeing memory, dams |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
Free MagazinesCisco NewsReceive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business. subscribe Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field. subscribe The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business. subscribe Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company. subscribe Total Telecom Total Telecom is "The Economist of the communications industry". subscribe |