3 Replies Latest reply on Jul 6, 2006 11:07 AM by silvermole

    Less memory

      How is it best to structure code so that it is less processor intensive? Should I use local or global variables? Does using removeMovieclip remove variables that are held within that MC? If I am not using a function how do I get rid of it or at least remove the variables from the computers memory?
        • 1. Re: Less memory
          blemmo Level 1

          local vars are always better than global vars, imho, maybe not in regards to the memory used, but in general. It might depend on the stuff you are doing what's better; personally, I try to avoid using globals.
          Variables in MCs are removed too when the MC gets removed, whereas global vars would remain until the player is closed, I guess. Flash has a garbage collector that removes local variables after use, so when you use vars local to functions, they should be deleted automatically when the function finishs. You can also use the 'delete' statement to remove vars that are not used anymore. To remove all variables in an MC without removing the MC itself, you can use the attached code. Note that it removes also the $version var, if it's present.


          • 2. Re: Less memory
            samdl1 Level 1
            nice bit of code I wouldnt have thought of that

            • 3. Re: Less memory
              Also, remember that if your using an onEnterFrame event that it will run continuously until you stop it, thus using processor power.

              consider deleting within the function using it

              delete this.onEnterframe