In the first reply to my slide view of a folder of JPEG's, zentara suggested to use blank() and read() to save memory.

That solution worked great! But now I want not only to view the pictures, but also to process them. In order to do that, the first thing I want to know is the width and height of the picture. I can easily obtain them by calling width() and height(). However with blank() and read(), I don't get the real width and height any more. What happened was that, Tk::Photo extends when a bigger photo is read(), but does not shrink when a smaller one is read, so it reports the biggest width and the biggest height (They are not neccessary to be the width and height of the same picture, as you may have a picture that is super wide, but short, and another one super high, but narrow.)

So I thought there must be a different way to solve the memory issue. I tried couple of things, but all failed. For example (see inline comment):

use Tk; use Tk::JPEG; use File::Glob ':glob'; my @jpgs = bsd_glob('*.jpg'); my $index = 0; my $mw = MainWindow->new(title => "JPEG"); my $b = $mw->Button()->pack(); $mw->after(1000, \&next_image); MainLoop; sub next_image { $b->configure(-image => undef); #effort to free memory eval { my $image = $mw->Photo(-format => 'jpeg', -file => $jpgs[$index]); $b->configure(-image => $image); $mw->configure(-title => $jpgs[$index]); $image = undef; #effort to free memory #undef($image); effort to free memory }; $mw->after(1000, \&next_image) if (++$index <= $#jpgs); }

Any suggestion?

2004-10-29 Edited by Arunbear: Changed title from 'how to free momery allocated for Tk::Photo?', as per Monastery guidelines


In reply to how to free memory allocated for Tk::Photo? by pg

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.