Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Avoid memory leaks in dojo?

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.

like image 630
Peter Bratton Avatar asked Sep 16 '11 14:09

Peter Bratton


1 Answers

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.

like image 185
Jani Hartikainen Avatar answered Oct 04 '22 20:10

Jani Hartikainen