unloadAndStop in Flash Player 10

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“.

Grant Skinner

The "g" in gskinner. Also the "skinner".

@gskinner

15 Comments

  1. 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.

  2. Thank bloody 2#$@#! It is a much brighter day today 😉

  3. 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.

  4. Happy to here this. Thanks for the great news.

  5. it’s 9am and I’m drinking champagne!!!

  6. 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 !

  7. I wonder why they just didn’t include this functionality in the current unload? Why force developers to refactor their code?

  8. 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.

  9. 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.

  10. very good to see.

    I had invisioned that such a command would be able to be called on a variable or MovieClip reference it’s self.

    It sounds as if their garbage collector knows all the references to an object. Couldn’t we tag something for deletion and have the garbage collector handle killing the references?

    The solution mentioned here is great for 3rd party, but one built for inner project use would also save a lot of time i think.

    or at least a way to trace the number of references an object has, to help us find our problems.

    anyway, 3 cheers for progress, I’m sure this was a lot of work, and it will help me a ton!

    I also love the other features that are coming with flash player 10. http://labs.adobe.com/technologies/flashplayer10/releasenotes.html

  11. This is a good step.

    I have a big memory leak too on my project. I haven’t installed FP10 because I am scared my work will no longer be compatible. I am using CS3 for now and I have no intention of buying CS4 right now.

    My question is the following. Does this “new” function also removes all children from a parent movie clip or parent SWF?

  12. Thanks for your persistence Grant. You are a great help!

  13. Is there any workaround for Flash Player 9… like a method coded to do everything the unloadAndStop method does? We gave minimum requirements to schools in August, so thousands of computers are stuck with Flash Player 9 for a multi-million dollar project. This HUGE BUG affects a major management system we’ve developed in Flash and kills our plans for some of its features, such as loading huge Adobe Captivate training videos into the interface, because now they’re almost guaranteed to sit there and rot until the player crashes… not to mention continuing to play in the background. Upgrading the player is simply not an option; I don’t understand how such a serious bug was allowed in ANY official release of the player.

  14. You can try the Janitor class I built a couple years ago. It requires that you manually register elements for cleanup, but it might help.

    gskinner.com/libraries

  15. How can I check if unloadandstop has actually removed my SWF/MC?

Leave a Reply

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