1

Do I have to worry anymore about all the listeners and class instances added to a movie clip that is no longer displayed on the scene?

I'm asking because I want to know if it makes sense to clean up after I'm done with a movie clip's instances on the scene.

IneedHelp
  • 1,630
  • 1
  • 27
  • 58

2 Answers2

2

Yes, you need to clean up.

Event listeners will keep the clip from being garbage collected if they are not removed.
Alternately, you can use weak event listeners. Then the listener will not prevent garbage collection as long as all other references to the clip are removed.

AS3: Weakly Referenced Listeners

Cadin
  • 4,275
  • 1
  • 14
  • 22
1

Realistically it depends on your app/swf file.

If your app is complicated/extensive and will be used for a lengthy session time wise then yes, you should be manually removing all references, stopping animations and nulling the instances.

Remember that even when the instance is off stage or removed from the display list, it still uses CPU and memory resources.

It is good working practice to do this but not really essential for smaller projects.

crooksy88
  • 3,849
  • 1
  • 24
  • 30
  • Thank you for the useful advice. I am dealing with a large site managing numerous resources and interactive elements, so I guess I have to clean up in order to keep it light on the client's machine. When you said I should stop animations, what were you referring to? Animation in Movie Clip instances that are no longer on the stage has no impact over the application, does it? – IneedHelp Jan 05 '12 at 18:37
  • 1
    Yes. Once an animating movieclip has been instantiated it will continue to animate despite being off stage. Although aimed at mobile optimization this is a very useful read. http://help.adobe.com/en_US/as3/mobile/flashplatform_optimizing_content.pdf – crooksy88 Jan 05 '12 at 19:45
  • Heh, I never imagined that would be the case. Thank you for the information and reference to content optimization. – IneedHelp Jan 05 '12 at 20:19