บทความเกี่ยวกับการหลีกเลี่ยงเขียน Javascript แล้วทำให้เกิด Memory Leak
หลักที่ผู้เขียนเขาแนะนำคือ
3. Set your XMLHttpRequest onreadystatechange handlers to null when you are done with them.
I use YAHOO.util.Connect for all my XHR connections and it uses a
polling mechanism instead of readstate, so I don’t need to do this
anymore. If you can switch to YAHOO.util.Connect (or
YAHOO.ext.UpdateManager built on top of it), I’d recommend it.
2. Clean up all your DOM event handlers on unload if there’s a chance they could reference a DOM object.
There’s no reason to manually do this when there are libraries that
do it automatically. I use YAHOO.util.Event for all my event handlers,
it handles this for me automagically. Other libraries (prototype, dojo,
etc) have some sort of mechanism to do the same thing, although I’m not
sure how effective they are. If you look at the leak images above once
again, you will notice almost all of them are in event related code of
those libraries.
1.