• Did you know…

    Event listeners and Dictionary’s support weak referencing facilities in Actionscript 3.0? Why the need for weak referencing?

    • potential performance gains
    • promote best practices in application cleanup strategies ( i.e. prevent memory leaks )

    Utilizing weak references does not necessarily mean that your application will be free from memory leaks. You, as the developer, are still in charge of cleanup tasks. Weak referencing, merely promotes objects to be garbage collected, when all references to that object no longer exist. As long as the objects in your code still maintain an object reference, the memory lifespan of that object will continue to persist in your application. So it is still up to you to make sure the preparations for cleanup are there and have been acted upon. Think of it as putting the trash outside on the curb for the garbage-men to pick up ( it’s not going to get picked up if you don’t put in the work to set it aside for the pickup ) ^_^

    Strategies which supplement good clean up tasks:

    • set the “weakReference” flag on addEventListener to “true”
    • use “removeEventListener” if you are finished using an event callback and don’t plan on using it again. This means, that you also need to keep track of when of when utilize “addEventListener”. Utilize event targeting or some other means of getting a reference back to the event target so you can safely remove an even listener and do any necessary object cleanup. I generally refer to this as “targeting” when utilizing events
    • make use of the “delete” keyword
    • if you using a Dictionary ADT ( abstract data type ), make use of the weak reference parameter found in the constructor of the Dictionary. It is set to “false” by default. Set it to “true”
    This entry was posted on Friday, December 26th, 2008 at 3:48 pm and is filed under Flex, QueueTip. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
  • 0 Comments

    Take a look at some of the responses we've had to this article.

  • Post a Comment

    Let us know what you thought.

  • Name:

    Email (required):

    Website:

    Message: