Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

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 Animation.pm 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 Animation.pm.

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.

      moritz,

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

      Tom

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (16)
As of 2015-07-07 21:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (93 votes), past polls