seith has asked for the wisdom of the Perl Monks concerning the following question:

Hi all, I have a question about Tk::Animation. See in the script I'm writing, which plays rendered frames from Maya, sometimes the same frames have to be played several times every time. So here's the problem: when you build the list of frames to be played (with add_frame), I believe you have to point to the image file. But then we have the absurd situation in which if you play the SAME teeny-weeny jpg image 30 times, it's going to end up taking several megs of memory!!! So my question is: Is there a way for Perl to know it already has the specified image in memory, and to just use it (without loading it again and taking as much memory)?

Replies are listed 'Best First'.
Re: A Tk::Animation question
by cbraga (Pilgrim) on Oct 15, 2004 at 23:46 UTC
    Is your problem that you have to add multiple copies of the same frame to an animation, thus making it big, or that the memory footprint simply grows when the animation is left playing?

    In the first case, you should probably create an image cache, loading each file only once and then passing the resulting Tk image objects to the animation object, multiple times if needed.

    In the second case, I assume you aren't creating new animation objects over and over but rather resetting it and re-playing the same animation object, right? If that's the case it could be a Tk bug, try destroying the animation object and creating it again from the frames after it's played each time.

    ESC[78;89;13p ESC[110;121;13p

      Oh boy do I feel silly! Thanks, that was the first case, and your suggestion of creating an image cache took care of the problem. Again, thank you, I was stuck and you got me going!