开发者

Finalisers in Adobe Flex 3

Using Ado开发者_如何学Cbe Flex 3, is there any way to specify a finaliser?


There is no concept of a finaliser/destructor in ActionScript 3, even at the AVM/bytecode level.


Even though there isn't such a thing as a destructor/ finalizer in ActionScript per se I would consider it good practice to have a method that frees all the resources in your class, when you no longer need them.

Garbage collection only picks up objects that are no longer needed anywhere, and it uses reference counting to determine when this is the case. So as long as there are unremoved event listeners, circular dependencies (objects referencing each other), etc., you may not notice it, but your memory usage will keep increasing, and the GC never frees up these resources at all.

Therefore, you should have a destroy() or finalize method that:

  • removes all event listeners
  • calls destroy() or finalize() on nested objects
  • deletes all strong object keys in dictionaries
  • sets all object type variables to null (it's okay for primitive values not to be reset)

For display objects, it is usually not a bad idea to call this method when Event.REMOVED_FROM_STAGE is dispatched.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜