Search code examples
memory-managementspriteeaseljscreatejsstage

Deallocate sprites properly


What are the proper steps to deallocate played sprite?

  1. Remove object from the stage
  2. Call stop() method on sprite
  3. Set sprite variable to null

Is it ok if I just remove it from the stage and don't stop it?


Solution

  • The Sprite instance receives its tick from the display list, so you don't need to stop it prior to removing it. To ensure it is available for garbage collection, simply remove it from the display list and ensure you null any references you may have created to it.