I ran your code, and see what you mean. Without alot of testing, it appears that you are keeping all the large full-sized photo objects, and that takes quite a bit of memory. In your code below, your are pushing the full-photo-objects into @imagelist. Then you are letting Tk::Thumbnail to make the thumbnails from them. You are wasting a heck of alot of memory in @imagelist.
{ my (@imagelist); foreach ( 0 .. $#filelist ) { print $filelist[$_], "\n"; my $temp = $mw->Photo( -file => $filelist[$_] ); push( @imagelist, $temp ); } eval { my $thumb = $mw->Thumbnail( -images => [@imagelist], -ilabels => 1 )->pack; }; warn($@) if ($@); }
So I would say you have a basic design problem. From my quick look, I would say you need to decide how many thunbs you want to display as a maximum. Then change your thumbnail generation method, and maybe "page them".

With Photo objects, you need to create a set of them once, and REUSE them. You can reuse a photo object with

$thumbs{0}->blank; $thumbs{0}->read($info{'admin'}{'thumbnail'});
So you could create a hash of %thumbs of say 100 keys, and that is what you display on each page....a 10 x 10 array of thumbs. And have a pager mechanism, to display as many pages as you need. But you don't fill in those subsequent pages, what you do is reuse the %thumbs and just reconfigure them with the next batch of thumbs.

Also when you create the thumbs, just make 1 "big-photo object" and reuse it in a loop, to make the thumb-objects. Then push the smaller "thumb-objects" into the @imagelist, instead of the huge full-photo-objects.

Here is a sample bit of code which shows how to make thumbnails in a loop, with just a single imager object. Now, I'm actually creating the thumbnails in the thumbs dir, but you could just push them into a hash. However....you will still reach memory limits if you try to push too many thumbs into a hash. So you must carefully think about juggling and reusing everything, so as to keep your mem use as low as possible. There are many ways to do this, so you have to find the modules which you like working with, and figure out how to use them in unison, without wasting objects.

sub make_thumbs{ my @pics = <pics/*.jpg pics/*.gif pic/*.png>; my $imager = Imager->new(); foreach my $pic (@pics){ my ($basename,$path,$suffix) = fileparse($pic,@exts); $info{$basename}{'key'} = $basename; $info{$basename}{'name'} = $basename; $info{$basename}{'pic'} = "pics/$basename.jpg"; #convert to jpg $info{$basename}{'thumbnail'} = "thumbs/$basename.jpg"; $imager->open(file=>$pic) or die $imager->errstr(); # Create smaller version my $thumb = $imager->scale(xpixels=>100); print "Storing thumbnail as: thumbs/$basename.jpg\n"; $thumb->write(file=>"thumbs/$basename.jpg", jpegquality=>30) or die $thumb->errstr; #Create resized picture my $resizer = $imager->scale(ypixels=>400); print "Storing resize as: pics/$basename.jpg\n"; $resizer->write(file=>"pics/$basename.jpg", jpegquality=>90) or die $resizer->errstr; } undef $imager; print "\n#################endofthumbcreation########################## +#####\n"; }

I'm not really a human, but I play one on earth. flash japh

In reply to Re: Memory issue while experimenting with Tk::Thumbnail by zentara
in thread Memory issue while experimenting with Tk::Thumbnail by atcroft

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.