in reply to Re: Tk photo display: memory never released
in thread Tk photo display: memory never released

no permanent growth with this one
#~ $image = $phwin->Photo(-file => $pic_file ); $image->read($pic_file, -shrink );

Replies are listed 'Best First'.
Re^3: Tk photo display: memory never released
by Discipulus (Canon) on Jul 04, 2016 at 10:11 UTC
    thanks Anonymous Monk,

    so the only way to efficiently load into a Tk::Photo object it is giving to it a filename to read ?

    What I can do if i want to manipulate the image before displaying it? I've used in the original program GD and Image::Resize to handle rotation, for example, but this implies that i'll later pass the photo's data as MIME::Base64 encoded string into the -data => part of the Tk::Photo configure.

    Thanks for your help

    L*

    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
      Temporary files? You'll have to try both/all and see what happens :)
        thanks for the suggestion but temporary files... no!

        but i'm very near to acceptable solution:

        # 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($re +sized->jpeg())); $photo_label->configure(-image => $image ); # system 'tasklist | grep perl'; # monitoring memory }

        The above is not leaking memory at the moment

        L*

        There are no rules, there are no thumbs..
        Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

        FWIW, through use Tcl::pTk::TkHijack; both versions leak, this  $image = $phwin->Photo(-file => $pic_file ); and this  $image->read($pic_file, -shrink  );

        This under

        tcl_version 8.6 tcl_patchLevel 8.6b1.2 tk_version 8.6 tk_patchLevel 8.6b1.2 tk_library C:/Tcl8.6/lib/tk8.6 Tcl::pTk 0.90 Tcl 1.02 $^V v5.16.1 $] 5.016001