http://www.perlmonks.org?node_id=778020

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

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