1
votes

I have been working on a flash game where I add sub-animations to a movieclip by attaching child movieclips. This creates a hierarchy of movie clips with different animations, but the result of that was that the parent movieclip ended up growing indefinitely and eating lots of memory. Is there a way I can optimize such animation? If bitmap caching works, would I be able to cache all the children which were added before runtime (e.g children movieclips which were added during design and before publishing the SWF).
PS I'm working with Flash Air 2.6 if that's of any help.

2

2 Answers

1
votes

Well, you're giving the answer yourself, Flash can do a lot but doesn't have unlimited amount of memory. However well designed your animation is, if the parent movie clip is "growing indefinitely" there will of course be a point where all will crash.

With the information given, I can only give you a general answer.

  • It is impossible to add an indefinite amount of children, but you can certainly give that impression if you keep removing the children that get out of scope.

  • Is there any way you can improve your design by avoiding repeats?

  • Do you work in the Flash IDE or do you use another IDE such as FlashBuilder, the latter has profiling tools that would allow you to check your application memory usage.

1
votes

To add to what Patrick said: Bitmap caching may well use even more memory, depending on how you do it. However, if you have multiple instances of the same thing, you can make only one of them and reuse its pixels everywhere, similar to what you see here http://flexdiary.blogspot.com/2009/12/riadventure-inspiration.html.

You might also want to look into object pooling http://blog.joa-ebert.com/2008/05/07/tweening-and-object-pools/.

However, when memory starts growing out of control, I usually suspect that you've caused a memory leak by adding listeners to objects and not removing them (so they can't be garbage collected). Other ways that you can cause memory leaks is by referencing an object through a dictionary or by using setTimeout without properly calling clearTimeout.