FLVPlayback doesn’t unload flvs, becomes memory hog

I’m posting this because I’ve wasted several hours pulling my hair out, frantically searching, and finding nothing. Maybe my search terms suck, but anyone with the same problem (with the as3 cs3 FLVplayback component, and lack of search skills), here is the solution:

Do not use multiple instances of FLVPlayback. It’s that simple. I had a class with a protected var _video:FLVPlayback; I would instantiate this class over and over again, play a video, and add a good 1-6 megs into ram everytime! Not so good… So, I changed that code to:

protected static var _video:FLVPlayback;

…and I was almost there. The FLVPlayback only keeps one video in ram (who’da thought?! :ooh: ). One important thing to keep in mind is that when attempting to play the same video twice in a row, the VideoEvent.READY doesn’t fire. So, just skip any “preparatory code” and go straight to playing the video. Just keep the current video path in a variable, and check against that every time you try to load a new one.

4 Responses to “FLVPlayback doesn’t unload flvs, becomes memory hog”

  1. chichilatte Says:

    Have you tried setting the activeVideoPlayerIndex property of your FLVPlayback instances to a non-zero value? Then you’ll be able to call the closeVideoPlayer(theIndexYouSet) method and have it actually work (it doesn’t work when the index is at the default 0). In as2, that was the only way you’d be able to get rid of an flv. Not sure if that is precisely the same as unloading an FLVPlayback instance from memory, but seems related. Especially considering the buggy unload() behaviour of the flash garbage collector, which suggests that you’d need to remove as much as possible from the instance before it can be gc’d.

    http://gskinner.com/blog/archives/2008/04/failure_to_unlo.html

    PS don’t forget to set the visibleVideoPlayerIndex property to the same index as the active index!

  2. Stefan Schmalhaus Says:

    Oh, how I wish I had found your blog earlier! It took me several hours to find out that VideoEvent.READY doesn’t fire if the video is still loaded.

  3. joe the plumber Says:

    my_video.videoContainer.attachVideo(null);

  4. Lawrie Says:

    You know, I spent about an hour trawling for ‘why flv won’t play twice’ before I found this and noticed that the READY event wouldn’t fire if the clip had already been loaded. I’m loading my clips randomly from an array and the chance was 1 in 8 that it would try and load the same one again.

    Unfortunately I couldn’t ditch using the READY event because I was using alpha tweens and all kinds of crap, and they won’t work unless a loaded video is READY. So I created a transparent .flv clip 1/24th of a second long and loaded *that* before I re-loaded my actual video clip.

    It’s a hacky fix, but it totally works.

Leave a Reply