Adobe has announced the addition of the new Loader.unloadAndStop() method for Flash Player 10. Here is the description from the beta 2 release notes:
unloadAndStop — This new ActionScript 3.0 API adds unload functionality similar to the unload behavior in ActionScript 2.0. After calling unloadAndStop on loaded content it will be immediately removed stopping all audio, removing eventListeners, and becoming inaccessible through ActionScript.
This new API addresses some of the issues I raised in my article "Failure to Unload: Flash Player 9's Dirty Secret". It doesn't enable content sandboxing, or provide a complete mechanism for explicit unloading, but it does make it much simpler to free a loaded SWF for garbage collection. It's still possible to prevent a SWF from being unloaded, but it's much more difficult to do by accident.
Kudos to the player team for putting this in. If you're concerned about this topic, please help Adobe out by testing this feature and reporting any problems.
Update: You can find more details on the Loader.unloadAndStop feature in my article "Additional Information on Loader.unloadAndStop".
Comments (9)
Great that it's finally in!
I actually just programmed an EventManager class last night (find it here: http://k2xl.com/wordpress/2008/07/02/as3-eventmanager-class-removealllisteners/
It has a function removeAllEventListeners() and can remove all listeners of an object, type of listener, function, or any combination of those.
I actually wanted to see your Janitor class but couldn't find it on the web.
Posted by: Danny Miller at July 2, 2008 04:45 PMURL: http://k2xl.com
Thank bloody 2#$@#! It is a much brighter day today ;)
Posted by: Kenny Bunch at July 2, 2008 07:22 PMURL: http://www.kennybunch.com
I was just coming back to comment on your original post about this as I just saw it. Agree, many many thanks to Adobe and the FP team, its great to see them reacting to our cries.
Posted by: Ian at July 2, 2008 10:06 PMURL:
Happy to here this. Thanks for the great news.
Posted by: Richard Summerhayes at July 3, 2008 02:12 AMURL: http://www.richardsummerhayes.net
it's 9am and I'm drinking champagne!!!
Posted by: paddy at July 3, 2008 02:22 AMURL:
I have been struggling with AVM1 Shell loading multiple AVM1 movies... components ... tabbing ... all kinds of issues. Hopefully this will help.
Worth a beer or 2 !
Posted by: DannyB at July 3, 2008 07:29 AMURL: http://www.nuff-respec.com
I wonder why they just didn't include this functionality in the current unload? Why force developers to refactor their code?
Posted by: Danny Miller at July 3, 2008 11:12 AMURL: http://k2xl.com
This still doesn't fix all of the garbage collection/memory leaking issues in FP, but it is a step in the right direction. I would like to see an AIR application run without an ever-growing memory footprint. That will be the day I celebrate for the dev team at adobe.
Posted by: Troy at July 3, 2008 05:25 PMURL:
so to use this unloadAndStop function, how do i enable it in the flash program? when I currently call it, it is unknown to flash.
Posted by: onsoup at July 8, 2008 10:57 PMURL: