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.
I apologize for the horrible coding style I use ... but I digress.# 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);
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
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |