Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

My fix for Tk::Animation

by TomKane (Beadle)
on Jul 07, 2009 at 21:00 UTC ( #778020=perlmeditation: print w/ replies, xml ) Need Help??

I was having a serious problem with Tk::Animation because running a series of very large animated gif's (e.g., 100-900Kb) would eventually bog down the system. I presumed that memory references were not being dropped so the memory was accumulating. That was unacceptable for an application I am developing.

I decided that I had not really looked as closely at the file as I should have. Well, I looked at how the animated gif's multiple frames were being managed and discovered that they were being placed into an anonymous array in the object's 'self'-hash. I couldn't find any place where the references were being deleted.

So I added a function that pops the reference elements off the array and lets them simply die away. I was then able to open and close multiple animated gifs, far more than I was ever able to do with the previous version of

Here is the function (it seems too simple):

sub del_frames { my $obj = shift; while( @{$obj->{'_frames_'}} ) { pop @{$obj->{'_frames_'}}; } }

In my application, I call del_frames after I stop using the animated gif and it is available and effective.

I hope that this may be useful to others. Tom

Comment on My fix for Tk::Animation
Download Code
Replies are listed 'Best First'.
Re: My fix for Tk::Animation
by moritz (Cardinal) on Jul 07, 2009 at 21:11 UTC
    I hope that this may be useful to others.

    Your chances of helping others might be higher if you submitted a patch to the Tk bug tracker. That way chances are that starting from the next release of Tk people won't even see that problem anymore.


      That's a good idea, I'll try it. Thanks.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlmeditation [id://778020]
Approved by moritz
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2015-11-28 06:04 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (738 votes), past polls