Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^3: Tk photo display: memory never released

by Discipulus (Canon)
on Jul 04, 2016 at 10:11 UTC ( [id://1167129]=note: print w/replies, xml ) Need Help??


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

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.

Replies are listed 'Best First'.
Re^4: Tk photo display: memory never released
by Anonymous Monk on Jul 04, 2016 at 21:31 UTC
    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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1167129]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (4)
As of 2024-04-20 00:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found