# global dummy photo my $image = $phwin->Photo(-file => '' ) or die $!; ... ################################################################################ sub next_pic { my $pic_file = shift @files; print "processing [$pic_file]\n"; #It's necessary to use the "delete" method to delete an image object #and free memory associated with it. Just using a lexical variable for #storing the image object and letting the variable to go out of scope #or setting to undef is not sufficient. # http://search.cpan.org/~srezic/Tk-804.033/pod/Image.pod $image->delete if $image->blank; my $gd_image = GD::Image->new($pic_file); my $small_w = int($gd_image->width * 0.2); my $small_h = int($gd_image->height * 0.2); my $resized = GD::Image->new($small_w,$small_h); $resized->copyResized($gd_image,0,0,0,0, $small_w, $small_h, $gd_image->width, $gd_image->height); $image->configure(-file => undef, -data => MIME::Base64::encode($resized->jpeg())); $photo_label->configure(-image => $image ); # system 'tasklist | grep perl'; # monitoring memory }