Scrubbing Movie Clip Fills Memory, Crashes Flash
Hello,
We have a Flex 4/Actionscript 3 application that involves "scrubbing" through a Movie Clip that is a swf file derived from a .mov file. This is accomplished by listenening to the change in value of an HSlider and calling gotoAndStop(n) on the Movie Clip repeatedly as the slider is dragged. The Movie Clip is 720 pixels wide by 405 pixels high.
It works great, however, after doing this scrubbing action a number of times, which is required by our application, we notice the memory (by tracing System.totalMemory and System.privateMemory) increasing dramatically; and when it gets to around 100 MB (though it's not the same every time), the Flash plugin in the browser will crash. Our assumption is that this happens because the scrubbing essentially loads dozens of bitmaps (each frame of the Movie Clip that is scrubbed over) very rapidly.
To try and ameliorate this, we have implemented aggressive garbage collection by calling System.pauseForGCIfCollectionImminent(0.1) on a timer every 10 seconds. This usually keeps Flash from crashing, however, sometimes the garbage collection itself causes Flash to crash, though it's not 100% predictable. We know this because we are tracing the garbage collection action and can see Flash crash when that action occurs.
It doesn't seem like we have a memory leak per se, as the free memory is eventually regained when forcing garbage collection.
So I have a couple of questions:
1) Is there any way to keep the memory from getting so large in the first place, given that we need this scrubbing functionality?
2) If not, is there a better way of tweaking the garbage collection so that it frees up memory while not itself causing Flash to crash?
