Freezing and unfreezing objects
Wow.. It’s been a long time since my last post! But don’t worry there is a lot of things I plan to talk about.
So let’s start with: Freezing and unfreezing objects
When I made all my tests, they were builded into FlashCS3 (which only build Flash 9 SWF)
And when playing the animations, it was really ugly.
But when you build the same animation in Flash CS5 (Flash 10 SWF), the animation is really clean and have absolutly no object waiting for GC. which is GREAT.
And if you start a SWF10 preloader and then load a SWF9 file? working great!
And if you start a SWF9 preloader and then load a SWF10 file? Bad GC!
So this post is still valid only if the first thing you run is a SWF9 animation in FP9/10/10.1
A few months ago (before FlashPlayer 10.1) I made some comments on the Adobe “Freeing memory” article about the need of manually stopping MovieClip at the end of a timeline animation in order to optimize CPU and memory.
Thibault pointed me to a very nice article (solution) to this problem.
Now that FP 10.1 is released, I just realized that it’s now even worst.
When a MovieClip playhead hit an empty frame on the timeline or a blank KeyFrame it remove itself (and its child’s) from the screen. But everything continues to play until the GC collect them all.
With FP 10, the ENTER_FRAME event is not dispatched anymore and you cannot instantiate a class after root object has been removed from stage, but the visual is still playing.
In fact, the MC doesn’t just keep playing. It keeps instantiating (allocating memory and processing time) clips and child’s and everything that would be required if the original clip wasn’t removed.
This means that even when you have 1000 DisplayObjects on stage, you might manage and compute 4000 in the background without knowing it.
Performance wise, in FlashPlayer 9 it was bad.
In FlashPlayer 10 it was badder… …and in 10.1 it’s just Badderdest!
One big difference since 10.1 : A timeline that has been removed from stage continue to play and dispatch AddedToStage and RemovedFromStage for object that shouldn’t be accessible, hence giving bad information on the stage current state.
Here is video of how this could impact the DisplayObject hierarchy, CPU, and memory.
In the video, wait for the green squares to appear… they are assets waiting for GC.
Blue square mean MC received a “RemovedFromStage” event, and gold square mean assets received “AddedTOStage” event.
Result in FlashPlayer 9 and 10
Result in FlashPlayer 10.1
As you can see, most the sprite are waiting for collection. You can also look at the stats on the bottom of the screen.
If you want to use my profiling tool: FlashPreloadProfiler
Full documentation is also on that page.
SVN source for the example showed in the videos are available on Google Code