Hello nzsvz9

> is taking up more and more memory with every image and never releases it

yes Tk when dealing with images indeed leaks memory! I had the very same problem with Tk::Photo

The trick is to reuse every object as much as possible, using undef against variables containing data using delete where it applies and, in my case, using a dummy empty file in $phwin->Photo(-file => "" )

In my picwoodpecker program I load many big pictures and finally got it not leaking memory. See the setup_draw_area sub to see it in action (search the program for various $tk_ph_image->delete if $tk_ph_image->blank and similar calls).

I asked a very similar question to your one when I noticed the leak: you can find it an interesting read and a possible starting point: Tk photo display: memory never released where the last post of the thread show my attempt to debug with a trivial attempt to show memory usage too. The code is full of comments and links useful to solve your problem.

Interesting part of the above perlmonks post:

# http://search.cpan.org/~srezic/Tk-804.033/pod/Image.pod # It's necessary to use the "delete" method to delete an image obje +ct 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 s +etting to # undef is not sufficient. # # $tk_ph_image is a Tk::Photo object $tk_ph_image->delete if $tk_ph_image->blank;

Please share your findings ;)

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.

In reply to Re: Losing my memory using Tk::Photo by Discipulus
in thread Losing my memory by nzsvz9

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.