2 Replies Latest reply on Mar 23, 2011 5:21 AM by Swiffmaz

    Garbage collection of "local" resources

    Swiffmaz Level 1

      Hello,

       

      in the following code is the garbage collector able to kill the timer or is there any magic that prevents flash player from doing so?

       

      private function initTimer():void
      {
      var timer:Timer = new Timer(1000, 0); // repeat forever
      timer.addEventListener(TimerEvent.TIMER, tickHandler); // no weak reference
      }

       

      Since the timer is local to initTimer() i assume the garbage collector may clean the timer sooner or later.

        • 1. Re: Garbage collection of "local" resources
          Flex harUI Adobe Employee

          It should go away unless you call start(), then the player hooks up an OS

          timer to it and it won't go away.

          1 person found this helpful
          • 2. Re: Garbage collection of "local" resources
            Swiffmaz Level 1

            This means, to break the lock of the Timer object we have to
            - explicitly call stop()
            or
            - wait until the timer has reached its repeatCount == currentCount (aka TimerEvent.TIMER_COMPLETE)
            or
            - ohters? (for example remove all event listeners?)

             


            Is this kind of locking a general approach? What about other classes?

             

            var fileReference:FileReference = new FileReference(); // in local scope
            fileReference.addEventListener(...)
            fileReference.download()/browse()/upload()

             

            urlLoader = new URLLoader(); // in local scope
            urlLoader.addEventListener(...)
            urlLoader.load()

             


            However i do not plan to take advantage of this kind of internal locking instead i try to hold the reference for the duration of the operation. But i am interested in what one need to do to allow flash player to work best (and keep memory usage low).