|Problems? Is your data what you think it is?|
Re: Losing my memory using Tk::Photoby Discipulus (Abbot)
|on Feb 04, 2021 at 20:29 UTC||Need Help??|
> 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:
Please share your findings ;)
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.