Some tips to consider to avoid memory leaks when destroying Dojo widgets:
- If the widgets are inside a "Container" like a ContentPane, Dojo provides functions like destoryRecursive()
- If you have created a dijit that you no longer need, you can destroy it calling destroy() / destroyRecursive(), etc and you are safe.
- You run into problems with memeory leaks when you wipe out the DOM node holding one or more widgets (eg innerHTML = x)
- Also, if you do connections using dojo.connect(evt, action), and the the evt is referencing a dijit function or event (eg button click). You are supposed to disconnect it prior to destroying a dijit
- Connect/disconnect and subscribe/unsubscribe handles that are leaked are somewhat minor... it would take a ton to really be an issue, but something to be aware of.
- destory()/etc cleans events declared during widget declaration (just not connect and subs)
- When you leave the page, everything gets cleaned up..But for large applications that never leave a "page", then memory leaks are an issue.
- Convention is to keep track of all connections made by a your your custom widget, and have your own destroy function to disconnect them. Subscribers are handled the same way.
Recommendations are by Karl Bishop during discussion on to properly clean up Dojo widgets. The worst thing to do is to use the DOM node to refresh the content of certain ID/div using innerHTML as this bypasses the widgets' destroy() or destroyRecursive() functions.
No comments:
Post a Comment