Please take our Survey
logo       

Choosing A Webhost:
A web hosting service is a type of Internet hosting service that allows individuals and organizations to provide their own website accessible via the World Wide Web. Web hosts are companies that provide space on a server they own for use by their clients as well as providing Internet connectivity, typically in a data center. Web hosts can also provide data center space and connectivity to the Internet for servers they do not own to be located in their data center, called colocation. more...

Gdk Pixbufloader not freeing memory: msg#00029

gnome.gtk+.perl

Subject: Gdk Pixbufloader not freeing memory


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>
Google Custom Search

Recently Viewed:
qnx.openqnx.dev...    gcc.libstdc++.c...    solaris.opensol...    information-ret...    misc.misterhous...    web.catalyst.ge...    apache.webservi...    redhat.release....    hardware.lirc/2...    kernel.autofs/2...    technology.sust...    linux.vdr/2003-...    editors.lyx.gen...    org.user-groups...    netbsd.devel.pk...    xdg.devel/2004-...    version-control...    jakarta.slide.d...    debian.packages...    creativecommons...    ports.ppc.embed...    bug-tracking.bu...   
Home | blog view | USPTO Patent Archive | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive 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