Wednesday, April 25, 2012

[YouTube-API] Trouble unloading AS3 Youtube player (Question from the hangout)

Hi Jeff,

Thanks for hosting the hangout!  I attached the code we took a look at in the hangout:

The AS3 Youtube player won't unload with the destroy code below, causing a memory leak.  I've attached a very simple runnable example of the problem with the code. Click the blue button to load and unload the video (let the player fully load, I removed the player-not-yet-loaded checks for readability)

Here is the relevant AS3 unloading code, in case anyone could see a problem on my end with it:
            if (mVideoLoader)
            {               
                mVideoLoader.
contentLoaderInfo.removeEventListener(Event.INIT, LoaderInitHandler);
                mVideoLoader.contentLoaderInfo.removeEventListener(IOErrorEvent.IO_ERROR, LoaderNoOp);
                mVideoLoader.contentLoaderInfo.removeEventListener(SecurityErrorEvent.SECURITY_ERROR, LoaderNoOp);

                var player:Object = mVideoLoader.content;
                player.removeEventListener("onReady", PlayerReadyHandler);
                player.stopVideo();
                player.destroy();
                player = null;

                mVideoLoader.unloadAndStop(true);
               
                if (mVideoLoader.parent)
                    mVideoLoader.parent.removeChild(mVideoLoader);   
               
                mVideoLoader = null;
            }

My current best guess is that the loader is a victim of this Flash bug: https://bugbase.adobe.com/index.cfm?event=bug&id=3071138 in which case the workaround in the player would be very simple.

Thanks, Matt Woomer

--
You received this message because you are subscribed to the Google Groups "YouTube APIs Developer Forum" group.
To view this discussion on the web visit https://groups.google.com/d/msg/youtube-api-gdata/-/81bRxTzkvv8J.
To post to this group, send email to youtube-api-gdata@googlegroups.com.
To unsubscribe from this group, send email to youtube-api-gdata+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/youtube-api-gdata?hl=en.

No comments:

Post a Comment