For long running applications in the browser using a toolkit such as dojo, I hear the point over and over again that dangling references must be avoided. But each language/framework has its own idiosyncrasies when it comes to memory management.
How can I avoid dangling references when building an app in dojo? I'm thinking of rules along the lines of "alloc" in iOS: how to use, and how to clean up after yourself when done.
I think the biggest thing which comes to dojo is that you should remember to disconnect any events you connect.
There's a simple pattern to this, for example in a custom dijit:
//connecting some events
this._events = [
dojo.connect(...),
dojo.connect(...)
];
Now, it's very straightforward to disconnect:
dojo.forEach(this._events, dojo.disconnect, dojo);
The same pattern applies when using this.connect
in a dijit.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With