Let's engage user with Flash platform
What lie beneath “useWeakReference”
I just read the most surprise secret of addEventListener workflow, wrote by Ted. He explained the process if we have use the default value of ‘useWeakReference’ ( fault by default ). The garbage collector will not remove its in almost situation. This result can be raise more unexpected performance for our application.
In the other hand, if we set this argument with ‘true’ value, the garbage collector will found its, then remove it as fast as it’s possible (this will not break common rule of object-oriented programming language)
You can read more about Ted’s exposing here.
ความจริงที่น่าตกใจก็คือ เมื่อใดก็ตามที่พวกเรา ได้ทำการ addEventListener แล้วไม่ได้ set ค่าอะไรให้กับ argument ที่ชื่อ useWeakReference (ซึ่งค่า default ของมันคือ false) นั่นหมายความว่า instance ของ object ที่เรานำมา subscribe หรือในอีกทางหนึ่ง เรียกว่า การนำ functionของ instance นั้นมา เป็น listener นั่นเอง ดังตัวอย่างด้านล่าง
1: this.addEventListener( Event.EventName, foo.fooFunction );
อย่างนี้ล่ะครับที่จะมีการ garbage collect ใดๆ ทั้งสิ้น แต่ถ้าหากเราเปลี่ยนเป็น
1: this.addEventListener( Event.EventName, foo.fooFunction , true );
อย่างนี้ล่ะครับนาย garbage collector จะเฝ้ามอง reference ของ foo จากมุมมืด มีโอกาสเมื่อไหร่จัดการทันที
No related posts.
| Print article | This entry was posted by Greendog on Wednesday, 17 September, 2008 at 7:41 am, and is filed under Experience, Reference. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |




about 7 months ago
I highly enjoyed reading your article, keep on creating such exciting stuff.