Memory Leak in Flex SDK 4.1 Spark VideoDisplay

In working on a small utility application (Adobe AIR) this week, I came across a pretty major memory leak in the beta Open Source Media Framework based Spark components in Flex 4.1 final.

The utility I am building grabs over 10,000 video clip records from our media repository and then systematically goes through and renders a still image of each clip. There’s actually a lot more to it than that and I’ll probably either write about or present on some of the neat tricks I am doing with this app soon, but for the sake of this article this is all you need to know.

I’m using s:VideoDisplay to grab data from an RTMP stream and also use the events present to manage the system method calls. Should be no big deal- but once the application hit 500-1000 out of the 10,000+ records, it would simply crash out. No good.

Using the Windows Task Manager, I could watch the memory usage in ADL skyrocket as each video was processed into a still image. Obviously something was up. Using the profiler in Flash Builder 4 I was able to isolate the problem to the org.osmf.* classes being used by the Spark VideoDisplay component.

It’s important to note here that while Flex 4.1 is certainly release quality, it (along with Flex 4.0) was released with components based on beta OSMF code. Flex 4.5, while not final by any means, does include the final OSMF 1.0 classes. I was able to download and compile the same project with Flex 4.5 and can happily say I have had no more memory leaks whatsoever. The application is running like a champ and processing thousands of videos without issue. Windows Task Manager shows that the memory used by ADL is being properly released and all is well.

As a side note, I could have written my own video display based on flash.media.Video or even used mx:VideoDisplay… but I wanted to get to the bottom of this :)

8 thoughts on “Memory Leak in Flex SDK 4.1 Spark VideoDisplay”

  1. Are you using the MAX Preview 4.5.0.17689 Sun Oct 24, 2010 milestone build?
    I am trying that but still have the memory leak problem.

    I just set video.source to different values to different buttons presses. Nothin else, and have this memory leak. Any other idea?

  2. I figured out a fix for the memory leak. You basically need to fix the component by creating your own.

    1) Copy the ActionScript from Adobe’s VideoDisplay class into a class of your own.
    2) Update all event listeners to use weak references.
    addEventListener(EVENT.TYPE,function,false,0,true)
    3) Add the following line to the bottom of the “removedFromStateHandler” function:
    removeChild(videoGateway);

    The memory leak should be fixed after this. Good luck!

Leave a Comment

Your email address will not be published. Required fields are marked *