All,

I have 2 perl Tk applications which bring in images (png, gif, jpg) and display them in a popup window, doing fun things with them, then when the user closes the popup window, the user goes on to do more work on another image in another popup window. Problem is the perl interpreter is taking up more and more memory with every image and never releases it, until it runs out of memory.

In the programs I have a hash called %TK in which I keep track of TK objects.I create a new unique key for each image the user wants to interact with, which when they select the image I then create a popup window, add a canvas into the popup, then add the image onto the canvas. Simple enough as shown in the code segments below.

# Create a TK object hash our %TK; # Generate a key $NVP{'Id'}=&newkey({'Join'=>''}); # Create the popupwindow $TK{'pw-'.$NVP{'Id'}}=$TK{'mw'}->Toplevel('-title' => $NVP{'Title'}) +; ... # Create the main canvas $TK{'canvas-'.$NVP{'Id'}}=$TK{'pw-'.$NVP{'Id'}}->Canvas(-background +=> $NVP{'Background'}, -bd +=> 1, -relief +=> 'sunken')->pack(-fill => 'both', + -anchor => 'center', + -expand => 1); ... # Create an image $TK{'image-'.$NVP{'Id'}}=$TK{'canvas-'.$NVP{'Id'}}->Photo($imagename +, -file => + $NVP{'File'}, -format => + $extension);
I apologize for the horrible coding style I use ... but I digress.

And the memory used by the program grows if I delete everything from the canvas by invoking $TK{'canvas-'.$NVP{'Id'}}->delete("all"); and still grows with each new image if I invoke $TK{'image-'.$NVP{'Id'}}->destroy(); and even continues to grow with each new image if I use $TK{'pw-'.$NVP{'Id'}}->destroy(); on the popup window.

The programs work great otherwise until they run out of memory ...

Any ideas?

I thank you in advance.


In reply to 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.